Thread: stdin question

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    197

    stdin question

    Code:
    #include <stdio.h>
    #define MAX=80
    
    int main(void)
    {
     char puffer[MAX];
    
     fgets(puffer,MAX-1,stdin);
    
     return 0;
    }
    I´ve the following question:
    If you enter more than MAX-1 characters, what does happen with the characters after MAX-1 then?
    I know that they will stay in stdin and be read in with the next call of e.g. fgets(), but what is, if the string´s length is too long for stdin?
    I was taught that there cannot be any buffer-overflow, when you use fgets() in the example above, but how is this been prevent?

    And can you then tell me how to find out the stdin-puffer´s size?
    Thank you!

    klausi
    When I close my eyes nobody can see me...

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    202
    You're simply telling fgets() to not pay attention to any number of characters greater than MAX-1. It pretty much is as simple as it looks.

    starX
    www.axisoftime.com

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    But the numbers of characters greater than MAX-1 are in stdin after calling it. If I call fgets() again it reads first these characters from stdin!

    klausi
    When I close my eyes nobody can see me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. stdin question
    By audinue in forum C Programming
    Replies: 12
    Last Post: 01-11-2009, 02:57 AM
  3. stdin question
    By SourceCode in forum C Programming
    Replies: 1
    Last Post: 04-10-2003, 08:50 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. stdin question
    By oomen3 in forum C Programming
    Replies: 6
    Last Post: 02-19-2003, 02:52 PM