C and pointer notes-sort out fgetc, GETC, getchar, fputc, putc, putchar ....

Source: Internet
Author: User

Input/Output Function Family

The family name can be used for all streams only for stdin and stdout

Getchar Character Input fgetc, GETC getchar

Putchar output fputc, putc putchar

Gets text line Input fgets gets

Puts text line output fputs puts

Scanf format input fscanf scanf

Printf format and output fprintf printf

Note:

Both fgetc and fputc are real functions, but GETC, putc, getchar, and putchar are macros defined by the # define command,

Therefore, parameters with side effects cannot be used when GETC, putc, getchar, and putchar are called.

The usage of fgets is as follows:

Char * fgets (char * string, int N, file * stream );

Fgets () is used to read characters from the file referred to by the parameter stream and coexist to the memory space referred to by the parameter string until a line break occurs, the end of the file is read, or n-1 characters have been read, finally, null is added as the string. If you read a line break or an EOF when the number of characters (n-1 characters) is not fully read ),The read operation ends. The string to be read last contains the line break, and another character is null. If the string cannot store the entire row, the next fgets call will start to read from the next character of stream without data loss.

FputsWrite a string to the specified file (the string end mark '\ 0' is not automatically written ')

GetsReads a string from the stdin stream until it receives a linefeed or EOF, and stores the read results in the character array pointed to by the STR pointer. Line breaks are not used to read strings,The read linefeed is converted to a null value and ends the string.

The gets function is insecure and does not limit the size of the input buffer, which may easily cause overflow. Therefore, do not use gets as much as possible.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.