C and pointer -- input and output function notes

Source: Internet
Author: User

In C language, input/output adopts the concept of stream, which is a block of memory. When a program runs, data flow is required, or the program needs some external parameters for calculation, or the program generates some data to be stored or transmitted to other programs, this is what we call the input stream (the former) and the output stream (the latter ). That is to say, the program is concerned with creating correct output byte data and correctly interpreting the byte data read from the input.
Since a stream has a buffer, it must have a buffer effect. When the operating system can determine that the current input/output has no relationship with the interaction, it uses the full buffer mode (refresh when the buffer zone is full). For example, when the standard input is used, no full buffer will be used. See the Code:
Viod F (){
Printf ("Enter data :");
Scanf ("% d", & N );
}
When we enter data, the screen displays "Please input data:", which means that when we input data from the standard input, the standard output will also be refreshed synchronously.
In C language, the stream is divided into text streams and binary streams. binary streams are used to directly copy the content in the memory and do not convert the content. They are generally used to compile network programs. In C language, stdio. H mainly provides stream manipulation functions.
Open stream
File * fopen (char const * Name, char const * mode );
File * freopen (char const * Name, char const * mode, file * stream );
Close stream
Int fclose (File * F );
Single Character Input:
Int getchar ();
Int fgetc (File * stream );
Int GETC (File * stream );
Output of a single character:
Int putchar (INT ch );
Int fputc (int ch, file * stream );
Int putc (int ch, file * stream );
Unformatted row input/output:
Char * fgets (char * buffer, int buffer_size, file * stream );
Char * gets (char * buffer );
Int fputs (char * buffer, file * stream );
Int puts (char * buffer );
Formatted row input and output:
Int printf (char const * format ,...);
Int fprintf (File * stream, char const * format ,...);
Int sprintf (char * buffer, char const * format ,...)
Int scanf (char const * format ,...);
Int fscanf (File * stream, char const * format ,...);
Int scanf (char const * string, char const * format ,...);
Error Report:
Void perror (char const * message); // when the standard library function fails to be called, the compiler will put an external integer variable errno (in errno. h) set the value, and then pass it to the user, prompting the error cause. perror simplifies this process. When an error occurs, perror outputs the message content, followed by a semicolon and a space, then print the information used to explain the error code of errno.
Void exit (INT status); // use exit_success or exit_failure for the parameter

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.