Thread: fflush(stdin)

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

    fflush(stdin)

    Why we are not recommanded to use fflush(stdin)?
    What diffecent between gets() and scanf()?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    fflush(stdin)

    scanf() inputs a formated string, gets() only inputs a string.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    10
    Gets will allow someone to overwrite memory you have allotted. Try to use fgets instead. There are quite a few posts on this. Example:
    Code:
    char this[15];
    fgets( this, sizeof( this ), stdin ); 
    //stdin used here is the standard input but could also be a file..etc

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Why we are not recommanded to use fflush(stdin)?
    Search for fflush ( stdin ) and posts by Prelude.

    >What diffecent between gets() and scanf()?
    scanf can be used safely if also used with discipline. There's no safe way to use gets.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. fread/fwrite
    By chopficaro in forum C Programming
    Replies: 6
    Last Post: 05-11-2008, 01:48 AM
  3. Searching Into Files
    By St0rM-MaN in forum C Programming
    Replies: 12
    Last Post: 04-26-2007, 09:02 AM
  4. Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC
    By tvsinesperanto in forum C Programming
    Replies: 34
    Last Post: 03-11-2006, 12:13 PM
  5. Linked List Need Help Urgent
    By ykchua in forum C Programming
    Replies: 5
    Last Post: 08-17-2004, 02:57 PM