palindrome

This is a discussion on palindrome within the C Programming forums, part of the General Programming Boards category; 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 ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > 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, 11:36 AM
  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, 04:50 PM
  4. Palindrome Coding trouble
    By TheLoneWolf32 in forum C++ Programming
    Replies: 3
    Last Post: 02-22-2003, 06:05 PM
  5. palindrome HELP !!!
    By TED22_8 in forum C Programming
    Replies: 23
    Last Post: 01-22-2002, 01:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21