C language character input and output

A buffer

  Unbuffered Input: after the character entered by the user for performing echo Now repeat printing characters, in other words, the program is waiting for the input character can be used immediately.

  Buffered input: most of the system is the input, will not be repeated printing characters just entered between pressing the Enter key, character entered by the user at this time is stored in a temporary storage area is called a buffer (buffer), the only type after the enter key, the program in order to use the characters entered by the user.

  Necessity buffer: 1 - the number of characters as a transmission block sent by one of these characters than the time saving; 2 - if the user inputs a wrong character, error correction can be performed via the keyboard, after the last pressing Enter before transmission to the input value of the program.

  [Unbuffered input, the input buffer have their own advantages, for use according to the specific application scenario. ]

  Classification buffer: fully buffered I / O and a line buffer I / O. [Fully buffered I / O: when to flush the buffer when the buffer is full (that is, to deliver content to the destination), a common scenario is the input file, buffer size depends on the system size is common 512 Byte and 4096 Byte; line-buffered I / O: Flushes the buffer in the event of a line break, usually line buffered keyboard input only after pressing the enter key will flush the buffer. ]

Second, files, streams, and keyboard input

  File (file) is stored in the memory area information. Files are typically stored in some kind of permanent memory (U disk, hard disk, etc.). C language contains many open, read, write, and close the file library functions. From the bottom surface of the relatively speaking, C can use the basic tool for the host OS file directly processing a file, the direct call function is referred to as the underlying OS I / O (low-level I / O). Because the computer systems are different, it is impossible for the general underlying I / O standard library created. At a high level is concerned, C may also be by standard I / O package (standard I / O package) to process the file, which involves the creation of a standard model and a set of processing documents standard I / O functions. Conceptually, C program dealing with the flow rather than directly with files.

  Stream (stream) is an actual input or output data streams mapped idealized, that different properties and different types of input, represented by a uniform flow properties. For the C program, the process is to open the file stream associated with the file, read and write operations are done by the flow.

  stdin stream: keyboard; stdout stream: screen output.

  getchar (), puthar (), printf (), scanf () member functions are standard I / O package.

Third, the redirect input / output

  funtion < file

  funtion: compiled executable system, whose function is to get the user input from the keyboard input information.

  file: text file name.

  '<': UNIX and Windows redirection operator.

  The functions of the command: the contents of file import function in the program. function program itself does not know (or care) input from the contents of a file or the keyboard, just know that this is the need to import the stream of characters, the characters one by one and read the contents of the print on the screen, know to read to the end of file (EOF ). [C the file and I / O devices on one level. ] 

  funtion > myfile

  funtion: compiled executable system, whose function is to get the user input from the keyboard input information.

  myfile: text file name.

  '>': UNIX and Windows redirection operator.

  The functions of the command: create a file named myfile, after which the function of the output (keyboard input copy) redirect to myfile file. If that existed before the myfile file, usually erase the contents of the file, and then replaced with the new content. For the function program, the beginning of the next line by pressing Ctrl + D (UNIX) or Ctrl + Z (DOS) to end the program.

  funtion < file > myfile

  Combination redirection, make a file copy. Order independent redirection operator command, that is, file, and the relative position of the operator and the variable myfile.

  [A redirection operators linked executable (command including standard OS) and a data file, a data file can not be used and further connected to a data file, a program can not be used in connection with another program. ]

  [Redirection operator can not read the files of the plurality of input disposable, one-time can not be directed to multiple output files. ]

  

Guess you like

Origin www.cnblogs.com/wyt123/p/10959589.html