Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fscanf return

Status
Not open for further replies.

rotovegasBoy

Programmer
Sep 16, 1999
88
NZ
the following won't work<br><FONT FACE=monospace>&nbsp;&nbsp;<br>if(fscanf(fp,&quot;%s %d&quot;, &buf, &numObjs)!=2)<br> bail_out;<br></font><br>I've printed out the value of the fscanf return with invalid input, which was 1, but the if statement still won't run whats going on?
 
Please elaborate your point. I didn't get your point . <br>I am giving the behaviour of fscanf() function<br><br>It returns the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. If an error occurs, or if the end of the file stream is reached before the first conversion, the return value is EOF for fscanf .<br><br>Let me know if still you have problem <br> <p>Siddhartha Singh<br><a href=mailto:siddhu_singh@hotmail.com>siddhu_singh@hotmail.com</a><br><a href=siddhu.freehosting.net> </a><br>
 
basic ally i'm reading in a file with a strict layout (it's a 3D object representation) different lines are supposed to have different layouts according to whether it's an object ore a triangle that makes up part of the object.&nbsp;&nbsp;If i encounter an error in the file ie a line with to few entries (eg only two entries for a 3D coordinate) my program should halt and print an error.
 
Yes then your logic is O.K. <br>Just do one more thing.Don't use & before buf . If it is a string and then check whether it worked or not. <br>if(fscanf(fp, <p>Siddhartha Singh<br><a href=mailto:siddhu_singh@hotmail.com>siddhu_singh@hotmail.com</a><br><a href=siddhu.freehosting.net> </a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top