-
palindrome
my program is as follows:
Code:
#include<stdio.h>
#include<string.h>
#define size 100
void main()
{
char strsrc[size];
char strtmp[size];
printf("\n Enter String:= ");
gets(strsrc);
strcpy(strtmp,strsrc);
strrev(strtmp);
if(strcmp(strsrc,strtmp)==0)
printf("\n Entered string \"%s\" ispalindrome",strsrc);
else
printf("\n Entered string \"%s\" is not
palindrome",strsrc);
}
what i did so far is wait for a user input and then check for palindromes. How do i change it so that I can use a file with a few lines to check each line if it is a palindrome and go on till the eof.
-
> void main()
main returns an int
> gets(strsrc);
NEVER use gets, always use fgets()
See the FAQ.
Also, when you use fgets(), the answer to how to read from a file becomes pretty self evident, you just replace the stdin with the open file of your choice.