c - While loop not terminating with '\0' -


This is a function to read the character's character from the file and then convert the string to a float, but when the loop

GSF 555 "Gas Filters - Ford Escort" 64.50 9 & lt; - This is what has been read with "64.50", but with "64.50"

PKL070 "Park Lens - Toyota Corolla" 36.50 8

while loop '/ 0' before Goes and also reads "9" and letters from the next line of data.

I have printf to see just what has happened.

  float getPrice (FILE * in) {char ch; Int i = 0; Four letters [10]; Ch = fgetc (in); Printf ("INDEX + NUMBER =% d% c \ n", i, ch); If (ch == '\ 0') ch = fgetc (in); Str [i ++] = ch; While (ch! = '\ 0' and & amp; i <10) {str [i ++] = ch; Printf ("index I =% d \ n", i); Ch = fgetc (in); Printf ("3% c \ n", ch); } Printf ("STRING =% s \ n", str); Return etf (str); }  

I'm not sure what I'm looking for in your post where \ u Talking, but I can see some problems.

First, fgetc returns an integer, not a character, it may be important to test for file offs because EOF is an integer with 1, not a character that is usually Assumes the value of 0-255. You can change the manifestation of f, not be an int, and not a four (do not worry, it will not affect the prints print from% c).

In addition, if you \ If you are trying to find out the end line of the test with 0, then this will not work. The end line is a new line, \ n Based on the underlying operating system, it can take two letters, not one. If you declare the new line as an int, but if you put ch all around, then it can not work, if you are trying to do this.


Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

c# - WPF Expander overlay used in ItemsControl -

class - Kivy: how to instantiate a dynamic classes in python -