[Webinar] Streamline your web hosting managementRegister Today

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 553

# fscanf help.

content of the txt;

3 // number of the lines below
asd 123
qwe 456
rty 890
2// same thing
..
..

fscanf( smth,"%d\n",&asd); // this takes 3

for (i=0; i<asd; i++ ) {
fscanf ( smth, "%s%d%d, a, &b,%c);
printf ....
}

so; output is ;

a=asd b=123 c=0
a=qwe b=456 c=0
a=rty b=890 c=2

how can c equals to 2 ? it is correct, and i want this yes but i did not understand fscanf ? i want to learn..
0
thefirstfbli
• 3
• 2
1 Solution

Commented:
In the first two cases, the second %d fails to match, so &c is not assigned.
in the last case, the second %d does match
0

Author Commented:
but if fscanf takes line by line it must be like this.

a=asd b=123 c=0
a=qwe b=456 c=0
a=rty b=2 c=0 // b is equal to 2.
0

Commented:
fscanf does not take line by line, it takes what your format asks for
0

Author Commented:
fscanf ( smth, "%s%d%d, a, &b,&c);  // error: not %c; &c...

it works like this ?

order is char int int ;

for first loop : "asd" "123" "NO integer in order, there is qwe so is 0 "
for 2n loop   : "qwe" "456" "No integer in order, there is rty so c is 0 "
for 3rd loop  : "rty " "890"  " yesss there is an integer in order = 2" ...
0

Commented:
yes
0

## Featured Post

• 3
• 2
Tackle projects and never again get stuck behind a technical roadblock.