First, you must understand the working principle of Fscanf:
Fscanf ends when it encounters \n. When it encounters \r, it will replace \r with 0.
Question:
There is a problem. You should pay attention to the newline character of your text. Under Windows, it is \r\n. Under Linux and Mac, it is \n, that is. Said there was a pit here.
It is normal for the code to read data files under Linux and Mac. Under Windows, you will encounter 0 at the end of various lines.
Solution:
Just use the built-in IDE to change the newline character of the opened data file set to LF (Linux, Mac newline character).
As shown below:
Recommended related articles and tutorials: golang tutorial
The above is the detailed content of When fscanf in golang reads a file, replace the carriage return with 0. For more information, please follow other related articles on the PHP Chinese website!