Thread: Noob needs help.

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    1

    Noob needs help.

    Hi guys, I'm currently teaching myself c via 'Sams Teach yourself C Programming in one hour a day'(Seventh Edition). I'm not sure if this is an error in the book or I'm typing something wrong but for some reason this code will not compile, and shows an error "'too few arguments to function 'fgets'"

    What would be the proper way to write this code? Thanks for the help.

    Code:
      /* ex02-05.c */
      #include <stdio.h>
      #include <string.h>
      int main(void)
      {
          char buffer[256];
    
          printf( "Enter your name and press <Enter>:\n");
          fgets( buffer );
    
          printf( "\nYour name has %d characters and spaces!",
                           strlen( buffer ));
    
         return 0;
     }
    Last edited by radzio; 10-30-2013 at 07:56 PM.

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Probably should be gets().

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I suggest that you ignore nonoob's suggestion as gets is not a proper way to fix the problem you are facing since it introduces a nearly insurmountable problem of its own, i.e., it renders your code vulnerable to buffer overflow. Rather, take a look at the link that camel-man provided and thereby change how you call fgets.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob to C need a little help!!!
    By sk8harddiefast in forum C Programming
    Replies: 8
    Last Post: 02-27-2010, 02:47 PM
  2. need some noob help
    By klmdb in forum C Programming
    Replies: 3
    Last Post: 01-16-2010, 11:03 AM
  3. need some C noob help
    By klmdb in forum C Programming
    Replies: 3
    Last Post: 12-20-2009, 02:37 PM
  4. noob
    By valthyx in forum C++ Programming
    Replies: 36
    Last Post: 07-22-2008, 01:04 PM
  5. noob help
    By Xenofon in forum C Programming
    Replies: 5
    Last Post: 10-05-2006, 05:42 AM