Solved

# fscanf help.

Posted on 2006-11-24
536 Views
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
Question by:thefirstfbli
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 3
• 2

LVL 84

Accepted Solution

ozo earned 300 total points
ID: 18010243
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

LVL 1

Author Comment

ID: 18010888
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

LVL 84

Expert Comment

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

LVL 1

Author Comment

ID: 18010981
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

LVL 84

Expert Comment

ID: 18010987
yes
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Title # Comments Views Activity
how to understand recursion 12 236
What is sub-make ? 2 102
Constant string is of type char *   ? 7 53
windows 10 pro lost profile. 10 83
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
###### Suggested Courses
Course of the Month8 days, 5 hours left to enroll

#### 737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.