c - difference for and while loops file i/o -


I write a code that takes value from a text file and writes it in a text file, so I Then stuck, I read the end of the file, I think both codes are correct, no difference is not a bit, although I am getting the difference. I am unable to understand, besides, is there any other way to read eof? Thanks for all the praised answers.

 for  (st = (fscanf (fptr_in, "% c", & amp; ch)); st == 1; st = (fscanf (fptr_in, "% C", & Amp; ch))   

Other

  st = (fscanf (fptr_in, "% c", and); while (st == 1) st = (Fscanf (fptr_in, "% c", and ch));    

Betting is different for in you are using the return value of fscanf which is int . When a Int is used as a conditional condition, it is like ! = 0 :

  int x; if (x) {} // equiv to: if (x! = 0) {}   

while in while you loop, you clearly Check if the return value is a 1 , therefore, if you want for your loop

  (= = st (= ( Fscanf (...)) == 1), then   

(or vice versa == 1 to while loop }) Should treat them the same way.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -