Home >Common Problem >What is the function of fgetc

What is the function of fgetc

hzc
hzcOriginal
2020-06-20 11:22:429772browse

What is the function of fgetc

#What is the function of fgetc?

The function of fgetc function is to read a character from the specified file. It is required that the file must be opened in the reading, reading and writing mode or the appending method

mode, write-only mode cannot be read.

fgetc is a function in computer C language. It means reading a character from the file pointed to by the file pointer stream. After reading one byte, the cursor position moves back one byte. Format: int fgetc(FILE *stream);.

The function of the fgetc() function is to read a character from the file specified by the file pointer. The ASCII value of the character is used as the return value of the function. If the return value is EOF, it means the end of the file. EOF is the end of the file. Flag, value is -1.
The statement "c=fgetc(fp);" reads a character from the file specified by the file pointer fp and stores it in the c variable, which is a character variable. Before calling the fgetc() function, the file to be read must be opened for reading or read/write, and the file should already exist.
The position of the read operation is also determined by the file's internal position pointer. For an existing file, when the file is opened, the file's internal position pointer points to the first byte of the file. At this time, the fgetc() function is called to read the first byte of characters. After reading one byte, the position pointer will automatically move backward by one byte. Then the fgetc() function is called again, and the read is the 2nd character. By calling this function continuously, you can read each character of the file, and you can use EOF to determine whether you have reached the end of the file.

Content description: The function returns the next character from the current position of the input stream stream and saves the file. The position indicator increases. The character is read as an unsigned character and converted to an integer value.
If the end of the file is reached or a read error is encountered, EOF will be returned. Since EOF is a valid integer value, when you operate a binary file, you must use the feof function to detect the end of file. You must also use the ferror function for error checking.
Reference: fputc(); getc(); putc(); fopen().

The function of the fgetc() function is to read a character from the file specified by the file pointer. The ASCII value of the character is used as the return value of the function. If the return value is EOF, it means the end of the file. EOF is the end of the file. Flag, value is -1.
The statement "c=fgetc(fp);" reads a character from the file specified by the file pointer fp and stores it in the c variable, which is a character variable. Before calling the fgetc() function, the file to be read must be opened for reading or read/write, and the file should already exist.
The position of the read operation is also determined by the file's internal position pointer. For an existing file, when the file is opened, the file's internal position pointer points to the first byte of the file. At this time, the fgetc() function is called to read the first byte of characters. After reading one byte, the position pointer will automatically move backward by one byte. Then the fgetc() function is called again, and the read is the 2nd character. By calling this function continuously, you can read each character of the file, and you can use EOF to determine whether the end of the file has been reached

The above is the detailed content of What is the function of fgetc. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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