Thread: skipping white spaces file and going back one line in a file

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    180

    skipping white spaces file and going back one line in a file

    I have a file with a bunch of numbers to read that i want to store in structure like a Person that has age, id and so on.
    There are 2 problems. First is that each line either has one of the things like age or id or it's just white space.
    Second is that i have 10 variables to fill for a structure iam using but not all of them will data for each variable in the file which is a problem because it's harder to figure out when i finished reading for the current structure.
    Is there any way to go back to start of previous line? Here's input for a clearer idea:

    Joe

    1

    32

    Charlie



    2

    Chris
    Something random like that...
    I was using trying with fgets and then isspace to detect white spaces but theres the problem that while iam skipping i will go to start of line of following person and i have pre condition in loop to start that in start of loop. Iam not aware of o wat to jump back to start of previous line that was read.

    Thanks in advance

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Well if you're going to be ignoring the white space anyways, you could use fscanf() instead.

  3. #3
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Are you sure you have empty lines, and not just odd-ish newlines? Maybe CR LF?

    Other than that, it looks like you have one value per line:
    Joe
    1
    32
    Charlie
    Missing field
    2
    Chris
    Missing field
    Missing field
    This should be very easy to parse.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing to a file and skipping line
    By LAURENT* in forum C++ Programming
    Replies: 2
    Last Post: 08-29-2015, 03:05 AM
  2. Replies: 2
    Last Post: 05-26-2012, 03:25 PM
  3. Skipping to a new line in an input file.
    By earth_angel in forum C Programming
    Replies: 15
    Last Post: 06-14-2005, 01:25 PM
  4. Skipping 2 next line when reading in from file?
    By aspand in forum C++ Programming
    Replies: 4
    Last Post: 03-21-2003, 10:22 AM
  5. Reading in text file into an array, white spaces...
    By error in forum C++ Programming
    Replies: 12
    Last Post: 01-14-2003, 09:39 AM