I think this code might work (index overflow check must be added) :
int ar[100], i, ch;
for (i = 0; fscanf(fp, "%d%*[\t ]%1[\n]", &ar[i], &ch) == 1; i++)
;
I think this code might work (index overflow check must be added) :
int ar[100], i, ch;
for (i = 0; fscanf(fp, "%d%*[\t ]%1[\n]", &ar[i], &ch) == 1; i++)
;
You should use code tags.
Does fscanf() return 1, or merely a positive number?
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
it returns the number of items scanned. the logic is inside the formatOriginally Posted by dwks
string, and it is as follows:
o scan a digit
o pass spaces and tabs, if any
o try to scan newline
so if fscanf returns 0 or -1, nothig had beed scanned and loop should stop.
if it returns 1, only digit had been scanned. fscanf() should eat all whitespaces up to the next digit.
if it returns 2, digit and newline scanned, so loop should stop.
Hi guys ,,
Now , I have another problem , I tried but it doesn't work , suppose we have data file as before
0 1 3 4
1 3
2 4
I don't need print out the 2ed row because is already in the first , I mean (1 3) in the 2ed row is duplicated , how can i do this !!!
Instead of printing them out, store what you have some place. (Linked List - See the FAQ / Prelude's corner, Google, board search, etc. Or an array, or...) Then run through what you have stored whenever you read something in and if it's already there, don't store it.
Quzah.
Hope is the first step on the road to disappointment.