Do I want to use fscanf if a line I'm reading is of varied length?

This is a discussion on Do I want to use fscanf if a line I'm reading is of varied length? within the C Programming forums, part of the General Programming Boards category; For example Code: 12 5 24.5 76.2 11.2 43.7 13 7 13.2 54.9 14 9 11.7 11.5 23.2 I know ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    93

    Exclamation Do I want to use fscanf if a line I'm reading is of varied length?

    For example
    Code:
    12 5 24.5 76.2 11.2 43.7
    13 7 13.2 54.9
    14 9 11.7 11.5 23.2
    I know the first two variables I need to store are
    Code:
    "%d %d"
    How should I go about reading each line in the text file and storing those doubles when each line is of varied length.

    Mind you, those doubles will be added up and divided by the number of them and stored in a variable which may make things easier.

    Thanks in advance.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >How should I go about reading each line in the text file and storing those doubles when each line is of varied length.
    Don't use scanf, it's not good about handling variance. A combination of fgets and strtod should work fine for you.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 05:05 AM
  2. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 08:38 PM
  3. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  4. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM
  5. line reading problem
    By papous in forum C Programming
    Replies: 2
    Last Post: 11-22-2001, 12:29 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21