Monday, 9 June 2014

Unformatted Console I/O Functions and Escape Sequence



Escape Sequences
The format specifier may also contain the sequences that begin with character ‘\’ (back slash) also known as escape sequences along with the text to be output and the variables whose value is to be printed. Every escape sequence has its own working and meaning which can be shown in the table below:
Escape Sequence
 Purpose
 Effect
          \n
New Line
It has the effect of carriage return and line feed. After this, the output starts with the new line.
        \t
Tab space
Moves over to the next tab space (normally eight space tab)
        \b
Back space
Moves the cursor one space left
       \r
Carriage return
Carriage return
      \f
formfeed
Advances to the top of the next page on printer.
      \a
alert
Produces a beep tone of speaker
      \’
Single quote    
Insert character ‘ in the output
      \”
Double quote
Insert character “ in the output
      \\
Back slash
Insert character \ in the output

Example using Escape Sequence is given below:

Source Code Window


Output Window


Unformatted Console I/O Functions
The functions that can deal with a single character and also with a string of characters are known as unformatted I/O functions. So the functions which deals with single character are called as character I/O and the functions which deal with input and output of set of characters i.e. string are called as string I/O functions.





a)   getchar ( )
 
This function reads a single of character from the standard input device i.e. keyboard. The read character is echoed on the screen and also the user has to press Enter key.

b)  getche ( )
  
 This function also reads a single character form keyboard. The character entered is also echoed but user has not press Enter key after typing a character. With this function as soon as the user types a character, it is immediately accepted.

c)   getch ( )

It also reads a character but neither this character is not echoed nor the user is required to press Enter key. It is used where user does not want to show the input.

d)  putchar ( )
   
This function is used to send a single character to the standard output device i.e. screen.

e)  gets ( )
  
 This function reads a string from the standard input device i.e. keyboard. The length of the string is limited by declaring a string variable. String entered can have multiple words and typing Enter key completes the input.

f)    puts ( )

  It is used to send a string to the standard output device i.e. screen.




No comments:

Post a Comment