gets debug

This is a discussion on gets debug within the C Programming forums, part of the General Programming Boards category; Well I guess I'm too isolated from the real world to know about the long known problems with "gets". I ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    28

    gets debug

    Well I guess I'm too isolated from the real world to know about the
    long known problems with "gets".

    I debugged this on my PC not on Unix.

    I loaded a real old version of TC to get the oldest compiler I could
    and made a real simple test program using "gets". Sure enough it
    caused problems if I entered too many characters. "Strlen" always
    reported the string length as 127 no matter how I defined the string
    array( char input[25] or char input[128] or char input[1024]. The
    string length was always 127 even if I held a key down for 2 minutes,
    must be a keyboard buffer limit.

    I got an illegal instruction message a couple of times and the TC blew
    up a couple of times.

    I think the reason I've never encountered this before is that we don't
    sell of otherwise distribute our software and it's always used in a
    very controlled environment.

    I'll go back to the Kernighan & Rithcie book to find a safer command.
    Any suggestions?

    Thanks for the help.

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    That's where fgets() plays it's role. It reads only maximum number of characters specified to be read, and not more, thus avoiding buffer overflow.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary not built with debug info - why?
    By ulillillia in forum C Programming
    Replies: 15
    Last Post: 12-11-2008, 01:37 AM
  2. makefiles - debug & release?
    By cpjust in forum C Programming
    Replies: 6
    Last Post: 10-26-2007, 05:00 PM
  3. Debug --> Exceptions in Visual Studio 2005
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-10-2007, 03:12 AM
  4. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 12:08 PM
  5. Ask about Debug Assert Failed
    By ooosawaddee3 in forum C++ Programming
    Replies: 0
    Last Post: 04-25-2002, 12:07 AM

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