This is my palindrome code in c:
#include <stdio.h>
#include <stdlib.h>
char toUpperCase(char c) {
if (c > 'Z') {
c -= 32;
}
return c;
}
int isPalindrom(char word[40]) {
int count = 0;
int letterCount = 0;
char lettersOnly[40];
for (int i = 0; i < 40; i++) {
char current = word[i];
if (current == '\n' || current == '\0') {
count = i;
break;
}
if ((current >= 'A' && current <= 'Z') || (current >= 'a' && current <= 'z')) {
lettersOnly[letterCount] = current;
letterCount++;
}
}
return 1;
}
It gives me an error that I set the variable "count" but didn't use it. I clearly used it tho.
How can I resolve this?
Your code only sets the value of count
(count = i
in the loop). It never reads this value, and thus it's safe to say that the program would have worked the same way had it been removed altogether.