Instead of this:
for (i = 0; i <= strlen(ch); i++) {
write this:
for (i = 0; i < strlen(ch); i++) {
With <=
it also copies the \0
, which makes strlen(newStr)
return only the length of the first line (because there is \0
after the first line).