Formatted and Unformatted Input/Output Function in C

There are two types of Input/Output function in C, which have some advantages as well as some disadvantages over each other. Each of them is used for a specific work to do.

LOGO

Formatted Function

One type of Input/Output function is Formatted function in which input/output is formatted as per our requirements.
There are two types of Formatted Functions:

  1. printf( )
    In a C program we use "printf( )" to print “character, string, float, integer, octal and hexadecimal values”  in the output screen. In printf( ) the format specifier will help the compiler to know whether the output value is int, float or of some other datatype. Also we can print anything we desire to print by putting that value under double coats ( " " ).

    Syntax:
    ⧫ printf("Format Specifier", arg 1, arg 2, arg 3, ........arg n);
     The above syntax is used when you want to print some value.
    Example 1
    Example 1

    OR
     printf("Enter the text you want to print");
    The above syntax is used when you want to print a text directly.
    Example 2


  2. scanf( )
    In a C program we use "scanf( )" to get the values as input to the program of different datatypes like int, float, double and many more. We use format specifier to differentiate the datatypes as Inputs.

    Syntax:
    ⧫ scanf("Format Specifier", arg 1, arg 2, arg 3, .....arg n);
     In scanf( ) you have to determine the type data you want to enter.
    Example 3
    Example 3
In scanf( ) we have to use '&' otherwise it will show you error.

Unformatted Function


Other type of Input/Output function is Unformatted function. This type of Input/Output function doesn't require any format specifier.
There are three types of Unformatted I/O functions:

🔺Character I/O
In this I/O function  it doesn't require any datatype because it will only work with CHAR DATATYPE. 
  1. getchar( ):

    This function can read one character at one time until and unless the user presses the "Enter Key". It can only store or take CHAR type input from the user.

    Syntax: Variable_Name = getchar( );
    Example 4
    Example 4
  2. putchar( ):
    This the function use to print one character in the screen at a time.

    Syntax: putchar( variable name );
    Example 5
    Example 5
  3. getch( ) & getche( ):
    These function read any alphanumeric character from the standard input device. The character entered is not displayed by the getch( ) function until the enter is pressed.

    Syntax: getch( );              getche( );
    Example 6
    Example 6
  4. putch( ):
    This function can print any alphanumeric character given by the user.

    Syntax: putch( variable name );
    Example 7
    Example 7
🔺String I/O
In this I/O function we take "String" as the input and also print "String" as output.
  1. gets( ):

    This function is used to take "String" as input until and unless the enter key is pressed.

    Syntax: char str[length of the string in number];
                  gets(str);
    Example 8
    Example 8
  2. puts( ):
    This function is used to print the string which has been stored in the program.

    Syntax: char str[length of str in number];              gets(str);              puts(str);
    Example 9
    Example 9
🔺File I/O

A file represents the sequence of bytes on the disk where a group of related data is stored. File is created for permanent storage of DATA. It is ready made structure.
I/O Functions
Some I/O Function



Check out our post on Format Specifier and others. ("FORMAT SPECIFIER" WILL BE ADDED SOON)

For giving some suggestion please comment us and check our "Contact us" page too. Also to give us any suggestion or for more update related to coding, it will be added in this Blog later on, so please get attached with this Blog. Thank you for your support and time..

Post a Comment

4 Comments