0

I'm trying to scan a line from a data file(txt format) it just contains a line of ints ex.
3457983257892

I need to scan the line and get the total number of individual ints.

Basically, 34563456 would total to 8. I'm not sure how to manipulate a while loop using fscanf and increment variable i. I think its that simple but it keeps core dumping.

What I have so far.

i = 0;
    while(fscanf(dFile, "%1d")!= EOF) {
        i++
    }
2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Salem
0

Well you're not using fscanf correctly, so no wonder it blows up.

int val;
while ( while(fscanf(dFile, "%1d", &val ) == 1 )
0

Not sure why you have two while loops? This is what I have so far and pretty much works except for the first number it reads is 1628741220

The first three numbers should be 1 5 2 (the rest are correct) but it goes
1628741220 2 3.

Here is what I have for code.

i = 0;
    int val;
    while(fscanf(dFile, "%1d", &val ) == 1 ,fscanf(dFile, "%1d", &val ) != 1 , i++)

I couldn't figure out how to incorporate your second while loop though...

0

> Not sure why you have two while loops?
Just copy/paste - nothing more

And your while loop is far too complex.
Put most of the code into the body of the loop.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.