Thread: fgets problem!

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

    fgets problem!

    this is my code:

    Code:
    #include<stdio.h>
    #include<string.h>
    #define size 100
    
    int main()
    {
    char strsrc[size];
    char strtmp[size];
    
    printf("\n Enter String:= "); 
    fgets(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);
    }
    when i try to compile it ... its gives me this error

    1.no new line at the end of file
    2.in function main : too few arguments to function 'fgets'

    would you please explain why this is happening and what the solution might be...

    by the way... this code should be able to read strings with whitespaces and punctuation marks in it ?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > 1.no new line at the end of file
    So put one in then
    Use the editor, go to the last line, press return and save.

    > 2.in function main : too few arguments to function 'fgets'
    fgets takes 3 parameters, just search for one of the 1000's of examples on the rest of the board, or just read the manual page.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    8
    now i got rid of the last two problems....

    but its giving me a new problem

    in function main
    undefined reference to strrev
    collect2: id returned 1 exit status


    what might be the problem now ? how can i solve it ?

  4. #4
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    what compiler/os are you using? it works under mine, in signature
    below, after one small change regarding fgets. fgets reads in
    the newline character '\n' if the entered string is less than the
    maximum allowed, so you need to remove this as when reversing
    the string this will be moved around as well. when calling
    fgets, use:

    Code:
    char *p;
    .
    .
    .
    fgets(strsrc, size, stdin);
    
    if ((p = strchr (strsrc, '\n')) != NULL)
            *p = '\0';
    back to your main problem, really need to know your details to
    help. it is in fact possible that your compiler does not have
    strrev - i once had a compiler that had math.h but did not have
    the pow () function!
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  5. #5
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    strrev isn't a standard c function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with fgets....
    By Huskar in forum C Programming
    Replies: 5
    Last Post: 03-29-2009, 10:13 AM
  2. Words and lines count problem
    By emo in forum C Programming
    Replies: 1
    Last Post: 07-12-2005, 03:36 PM
  3. problem with fgets
    By learninC in forum C Programming
    Replies: 3
    Last Post: 05-19-2005, 08:10 AM
  4. print problem while using fgets()
    By learninC in forum C Programming
    Replies: 12
    Last Post: 05-15-2005, 09:29 PM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM