Thread: gets warning on gcc

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    68

    gets warning on gcc

    Sorry if this has been asked, my program works correctly however gcc gives this warning message after compilation.

    /tmp/ccCSFstj.o(.text+0x29): In function `main':
    : warning: the `gets' function is dangerous and should not be used.
    My book only says gets should be used with caution because it can go over the allocated buffers is there anything else I should know?

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    There is nothing else to know except, don't use it. Ever.
    Use fgets()

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    16
    If you have something as:
    Code:
    gets(buffer);
    Replace it with:
    Code:
    fgets(buffer, sizeof buffer, stdin);
    Remember this and never ever use gets() again.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > My book only says gets should be used with caution
    Burn it.

    Or perhaps the book meant to say the book itself should be used with caution.

    Title and author please.

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    68
    Sams Teach Yourself C in 21 Days - Bradley Jones and Peter Aitken. the book has been much better than my other which is just too old, and teaches a few bad habits.

  6. #6
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Ah, Sams. Gawd bless the cheeky monkeys. Always one to dare to do the impossible (Claim to teach complicated programming languages in the space of between a day and 3 weeks, which most of its customers seem to think is a guarantee)...

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    68
    That seems to be the wrong edition of the book I have Sams Teach yourself C in 21day Ed6. not the VC++ one. I dont expect to learn C in 21days that wasnt the aim of me buying the book its impossible to learn any language in 21days most are too big.

  9. #9
    ---
    Join Date
    May 2004
    Posts
    1,379
    No one is blaming you for reading/buying it. Lots of people still do get these kinds of books not knowing how bad they really are.

  10. #10
    The C-er
    Join Date
    Mar 2004
    Posts
    192
    Yes, imagine my dissapointment when I didn't manage to learn Linux in 10 minutes!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM