io - C - program checks only the first word in file -
c beginner here. suggestions? have file containing text , have find words can read same forwards , backwards (palindromes) example rotator, eye , on. problem program checks first word in file. in advance.
that code now:
#include <stdio.h> #include <string.h> int main() { char buffer[255]; char one[255]; char two[255]; char *fp; fp = fopen("duom.txt", "r"); fgets(buffer, 255, (file*)fp); sscanf(buffer, "%s", one); strcpy(two, one); strrev(two); if(strcmp(one, two) == 0) printf("%s palindrome\n", one); else printf("%s not palindrome\n", one); return 0; }
your code run once, need put main analysis inside while loop.
i'll let test loop , how check next word.
Comments
Post a Comment