Thread: palindrome

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    8

    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.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in Recursive String Palindrome Code
    By clegs in forum C Programming
    Replies: 13
    Last Post: 12-21-2008, 12:36 PM
  2. Is it a Palindrome?
    By xp5 in forum C Programming
    Replies: 3
    Last Post: 09-06-2007, 05:26 AM
  3. bool palindrome definition
    By justinc911 in forum C++ Programming
    Replies: 3
    Last Post: 11-26-2003, 05:50 PM
  4. Palindrome Coding trouble
    By TheLoneWolf32 in forum C++ Programming
    Replies: 3
    Last Post: 02-22-2003, 07:05 PM
  5. palindrome HELP !!!
    By TED22_8 in forum C Programming
    Replies: 23
    Last Post: 01-22-2002, 02:14 PM