code help for file program

This is a discussion on code help for file program within the C++ Programming forums, part of the General Programming Boards category; Hi, I am new to this forum and C++ programming. I wanted some help for coding a program so as ...

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    7

    code help for file program

    Hi,
    I am new to this forum and C++ programming. I wanted some help for coding a program so as to access some data from a file.

    I want to write a function lets say fn1() which will scan a line everytime the function fn1() is called.

    Code:
    13233266  14  16 25.80  23.50 24.40  58.76
    13233486  14  12 24.74  24.73 23.88  60.04
    13233584  12  14 25.30  22.48 23.77  58.71
    13233804  14  14 25.25  23.27 23.65  58.77
    13233909  10  14 25.37  22.54 24.01  58.15
    13234117  16   8 24.66  21.75 23.03  58.60
    13234227   6  16 25.52  23.58 25.15  59.14
    13234331  12  20 25.21  23.68 24.36  59.59
    these are the data present in values.txt

    I have to write fn1() such that for the
    first time fn1() is called it should input first line,
    second time its called it should input second line

    can anyone help me... how should i use fseek to jump to the line i want...i can handle with fopen and fscanf..
    But the major problem is Jumping to the required line

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,833
    Use getline() to read a whole line, then parse that line to extract the fields of information.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic file read, file write program
    By starwarsyeah in forum C++ Programming
    Replies: 5
    Last Post: 02-28-2011, 03:23 PM
  2. program that reads text from a file and encodes the file by.....
    By kendrakay2000 in forum C++ Programming
    Replies: 5
    Last Post: 12-05-2010, 06:06 PM
  3. Replies: 2
    Last Post: 03-04-2010, 04:19 AM
  4. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  5. can you all take a look at my program code
    By jobolikescake in forum C++ Programming
    Replies: 7
    Last Post: 09-06-2002, 11:21 PM

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