Sunday, February 20, 2011

Learn to make proper Input/Output operation in C

             Input/Output operation are very important in C language to  initialize the variable and to put the desired output in C. In every C program there is a use of input/output functions.
          
There are three types of input/output operations :-
  1. Formatted    Input/Output
  2. Character     Input/Output
  3. String           Input/Output 
    Formated input/output function : 
                 


    There are two function printf() and scanf() 

    printf() function:-
    This function is used to display the output to the screen  the  string which is to be printed as it is usually .
    Syntax
    printf("printable string ",argument1,argument2,....,argumentN);
    • printable string  can be any printable character which is written between " ".
    • It can be also be the character of escape sequence starts with (\).the are generally used for moving cursor
    • formats specifier which starts  with % symbol then format specifier are used to print some useful value
    scanf() function:-
    This function is used to take the input value from keyboard or to initialize the variable at  run time of program 
    Syntax
    scanf("printable string ",&argument1,&argument2,....,&argumentN);

    • For scanf(), function "printable string " is  mostly format specifier with % symbol .
    • &argument1,&argument2,....,&argumentN  are the address of the argument variable , initialized value are stored memory ,which has corresponding address of arguments.
    Character Input/Output function : 

    • This type Input/ Output function is used to get one character at a time from the input device such as keyboard and put output of one character on the screen . 
    • getchar and putchar function are used for such operation in C
    getchar() function:-
    syntax
    variable_name= getchar();

    This function is used to accept one character from the keyboard and it should be of C character set, but character may or may not be printable .

    putchar() function:-
    syntax
    putchar(variable_name);

    This function is used to print one character on the screen and it should be of C character set, but character may or may not be printable .

    String  Input/Output function : 

    • The  function is  used to accept the string from the keyboard and print the string to the screen , String  refer to one whole sentence it can be on word also. 
    • this function reads the string till the newline  character is encountered or enter key is pressed.
    • gets() and puts() are string input/output function .

    gets() function:- 
    syntax
    gets(variable_name)
    It accepts the text till the (\n) newline character is encountered or enter key is pressed,Variable must be a array of string.


    puts() function:- 
    syntax
    puts(variable_name)
    This is used to print the string on the screen , it also assign or appends the (\n) newline character at the end of string. 

          Remember

    • Actually puts() and putchar() function can also be execuated by use of a scanf() function. 
    •  string function do not use &  symbol while passing argument .
    • this are all functions of <stdio.h> header file 








      No comments:

      Post a Comment