|
-
February 12th, 2004, 04:06 PM
#1
fscanf issues
hello
i am struggling a bit with fscanf and hope someone can assist me here.
my goal is to just open a file
read each value and store and print one of two values START and FINISH
the trouble i am having is the issue of having only one
number on a line and not two.
say i have the following data file
data.dat
----------------
0
1 234
22 3456
333 4567
4444 56789
0
0
i just want to read the file and out put
start = 0 and finish = BLANK
start = 1 and finish = 234
start = 22 and finish = 3456
the problem i am having is that it prints it out mixed up
the output i get is (where finsih should be it reads the next start)
start = 0 and finish = 1
start = 234 and finish = 22
start = 3456 and finish = 4444
my code is as follows:
while ( (c = getc (fPtr)) != EOF){
fscanf(fPtr, "%d %d", &start, &finsih);
printf("start= %d and finish= %d",start,finish);
}
this also skips the first line
my question is how do i discern between a line with 2 fields VS a line with 1 field
meaning can i do a count or check on what fscanf
brings in or does fscanf return the number of fields it has read
something like (this is not true code)
open file
read file
while not EOF
fscanf(%d %d, start, finish);
if finsih has nothing then dont print out finsih
else print both out
please help im quite frustrated at C right now
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|