for (i = 0; i < size; i++) {
if((string[i] >= 65 && string[i] <= 90) || (string[i] >= 97 && string[i] <= 122) || string[i] == 10) {
sec_str[j] = tolower(string[i]);
putchar(sec_str[j]);
j++;
}
}
printf("%s\n", sec_str);
This is my code, was trying to copy one string to another one, stripping all non letter cases, and that works fine for me, I use putchar(sec_str[j]) to check and they are all good, but when I check with the printf("%s", sec_str), the output was a mess. something like this:
asantaspotstopsatnasa
asantaspotstopsatnasa
twasbrilligandtheslithytoves
twasbrilligandtheslithytoves
����r�$
yobananaboy
yobananaboy
ndth
neveroddoreven
neveroddoreven
h
thetimehascomethewalrussaid
thetimehascomethewalrussaid
����t�r�$
and the printf should print
asantaspotstopsatnasa
twasbrilligandtheslithytoves
yobananaboy
neveroddoreven
thetimehascomethewalrussaid
to be correctly