Thread: fgets ?

  1. #1
    Registered User marrk's Avatar
    Join Date
    Sep 2006
    Posts
    23

    fgets ?

    My question is, why when we use a function fgets() in that kind of way
    Code:
    if(fgets (buf, sizeof buf, stdin) != NULL)
    {
          //stuff
    }
    there is no else statemant?

    just curious

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What are you talking about? If you want an else write one.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2006
    Location
    Da World
    Posts
    6
    The stuff is executed only if fgets() gets a non-null value from the standard input.
    If you want some error to be printed in case a null string was input try this :
    Code:
    if(fgets(mychar, sizeof(mychar), stdin)
    {
          //stuff
    }
    else
    {
           //print error
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fgets not working after fgetc
    By 1978Corvette in forum C Programming
    Replies: 3
    Last Post: 01-22-2006, 06:33 PM
  2. problem with fgets
    By learninC in forum C Programming
    Replies: 3
    Last Post: 05-19-2005, 08:10 AM
  3. problem with fgets
    By Smoot in forum C Programming
    Replies: 4
    Last Post: 12-07-2003, 03:35 AM
  4. fgets crashing my program
    By EvBladeRunnervE in forum C++ Programming
    Replies: 7
    Last Post: 08-11-2003, 12:08 PM
  5. help with fgets
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-17-2001, 08:18 PM