the issue i have is that the code keeps adding letters after the 'for' code, if i write "ni pratar bra latin" it will become "nipratarbralatintin" with an exta "tin"
int ret1;
int size = 0;
int i = 0;
char ch[100];
printf("WELCOME USER
");
printf("ENTER A SENTENCE OR A WORD FOR THE PROGRAM TO START.
");
printf("THE PROGRAM WILL CHECK IF YOUR SENTENCE / WORD IS A PALENDROME");
printf("
");
scanf(" %[^
]s", &ch);
Removes spaces aka the part im having issues with
for (i = 0, size = 0; i < strlen(ch); i++) {
ch[i - size] = ch[i];
if (ch[i] == ' ')
size++;
}
ch[i] = '';
ret1 = isPalindrome(ch);
int quit;
if (ret1 == 1)
// 1 means string is palendrome
printf("
YOUR SENTENCE/WORD: %s IS A PALENDROME", ch);
else if (ret1 == 0)
// 0 means string is not palendrome
printf("
YOUR SENTENCE/WORD: %s IS NOT A PALENDROME", ch);
question from:https://stackoverflow.com/questions/65920652/i-want-to-remove-spaces-from-a-string-to-check-if-its-palendrome-but-it-keeps-ad