When fscanf in golang reads a file, replace the carriage return with 0

王林
Release: 2019-12-07 10:24:18
Original
3357 people have browsed it

When fscanf in golang reads a file, replace the carriage return with 0

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:

When fscanf in golang reads a file, replace the carriage return with 0

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template