Thread: fgets()

  1. #1
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312

    fgets()

    I was experimenting with File I/O in C a bit and I tried to use fscanf() to read a string WITH whitespaces, so it reads only one word. I now use fgets() in my testing program, but I read on this board it was "bad" to use gets(). Why? Is it also "bad" to use fgets() ?
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    fgets() is the preferred method over gets().

    From the FAQ of this site: http://faq.cprogramming.com/cgi-bin/...&id=1043284351

  3. #3
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127
    http://faq.cprogramming.com/cgi-bin/...&id=1043284351
    fgets is ok
    edit:MacGyver is faster

  4. #4
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Ah of course! I looked at c-faq.com and at cplusplus.com, but I forgot this site
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

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