Thread: Fgets + sscanf

  1. #1
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198

    Fgets + sscanf

    I am reading input from a file using fgets, and then using sscanf to put what was read into a variable.

    The problem is now I have an area which can contain upto 2000 chars.

    The problem is how can use fgets in combination with sscanf within a loop.

    I can stop reading when two consecutive periods are found.

    Any input would be appreciated.

    Thanks
    -MethodMan-

    Your Move:Life is a game, Play it; Life is a challenge, Meet it; Life is an opportunity, capture it.

    Homepage: http://www.freewebs.com/andy_moog/home.html

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    So have a 2001 byte read buffer.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198
    But every time sscanf reads it will only read one word. My problem is knowing how to use sscanf when Im not sure how many words it will read.
    -MethodMan-

    Your Move:Life is a game, Play it; Life is a challenge, Meet it; Life is an opportunity, capture it.

    Homepage: http://www.freewebs.com/andy_moog/home.html

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    sscanf won't test for consecutive characters (assuming you were thinking of using the %[...] specifier). You'll have to do it manually with strstr and friends, or assume that a single period will just not happen.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem using sscanf fgets and overflow checking
    By jou00jou in forum C Programming
    Replies: 5
    Last Post: 02-18-2008, 06:42 AM
  2. fgets, sscanf question.....
    By Ash1981 in forum C Programming
    Replies: 12
    Last Post: 01-06-2006, 01:31 PM
  3. sscanf (I think)
    By RyeDunn in forum C Programming
    Replies: 7
    Last Post: 07-31-2002, 08:46 AM
  4. fgets && sscanf
    By GaPe in forum C Programming
    Replies: 3
    Last Post: 12-24-2001, 05:39 PM
  5. SSCANF help
    By mattz in forum C Programming
    Replies: 7
    Last Post: 12-10-2001, 04:53 PM