Solved

fscanf help.

Posted on 2006-11-24
5
520 Views
Last Modified: 2008-02-01
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
Comment
Question by:thefirstfbli
  • 3
  • 2
5 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 300 total points
Comment Utility
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

by:thefirstfbli
Comment Utility
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

by:ozo
Comment Utility
fscanf does not take line by line, it takes what your format asks for
0
 
LVL 1

Author Comment

by:thefirstfbli
Comment Utility
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

by:ozo
Comment Utility
yes
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
In desperate need of help 8 129
libcurl and C++ - Post JSON Data 8 1,060
How to get time_t value that is a week old 6 154
Problem to save 10 120
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now