Thread: convert printf / structure

  1. #1
    Registered User Max's Avatar
    Join Date
    Jul 2002
    Posts
    110

    getline / sscanf

    What is the difference between fgets, getline and sscanf

    and why getline and sscanf are usually used together?
    Last edited by Max; 10-25-2002 at 06:26 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The difference is, 'getline' is non ANSI, and 'fgets' is an ANSI standard function.
    This sounds like homework to me, so how about you read the following. It'll be educational:

    fgets is your friend.

    gets should never be used. Ever.

    sscanf is handy.

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

  3. #3
    Registered User Max's Avatar
    Join Date
    Jul 2002
    Posts
    110
    Thanks Quzah....by the way it is not homework...I just wanted to know the relationship.....I was always confused....but why do we need sometime to use getline followed by sscanf??

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >but why do we need sometime to use getline followed by sscanf??
    I don't know of any commonly used getline outside of C++, but fgets and sscanf is used a great deal because it is safer to read a line from input and then parse it yourself instead of hoping that it is formatted correctly for scanf.

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. making it portable.....?
    By ShadeS_07 in forum C Programming
    Replies: 11
    Last Post: 12-24-2008, 09:38 AM
  4. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  5. Replies: 4
    Last Post: 04-01-2003, 12:49 AM