Monday, April 22, 2013

C-Programming(Input-Output)


INPUT\ OUTPUT
Ø  In general, it is very necessary to read input value from keyword and to display output value on monitor. It can be achieved using I\ O statement in “C” language.
Ø  < stdio.h > Standard Input Output Header File : - It contain all functions related to input /  
                 Output operations.
Ø   Note:  In any computer language the name of function is always followed by open and close
     Parenthesis‘( )’.                               
printf( ):- It is a formatted function of < stdio.h > header file which is used to print some                 Message or valves on monitor.
Syntax1:-
printf(“hello”);àwhich is used to display any user define message on consol screen.
Ex: 1) - printf (“Hello India”);
              O/P: - Hello India
   Syntax2:-
 printf(“format specifiers” ,argument list);àwhich is used to display output values on consol screen.
Ex 2) - int X=5;
              char Y=’A’;
              float Ch=10.5;
              printf ( “%d  %f   %c” , X , Y , Ch );
              O/P        5   10.5   A
Ex 3) - printf (“Average = %f” , avg );
            O/P:    Average = 27. 8
scanf( ) :- It is a formatted function of <stdio.h> header file, which is used to scan or enter                  Some values from keyboard on moniter.

Ø  It performs two operations.
1)      Read data or accepting data from the input device keyword.
2)      Store the data in appropriate memory location.
Syntax:-
scanf(“format specifiers”, & argument list);
Ex:-
          int     X;
          char  Ch;
          float  Y;
          scanf ( “%d%f%c” , &X , &Y,&Ch);
Format specifier: - These are the special elements in “C” language used to identify type of data from keyword.
Ø  Format specifiers should be enclosed between double quotes.
Ø  Each “format specifier” starts with the character (%).
Ø  The argument list contains a list of variables.

Formatted specifiers /characters in “C”
          Data type                     Specifiers
               int                              %d, %i
              Char                             %c
              Float                            %f
              String                         %s
              Unsigned int               %u
              Long int                       %ld
              Double                        %lf
              Long double                %Lf
              Octal number               %O
              Hexadecimal (lower case latter)                %x
              Hexadecimal (upper case latter)                %X

Ø  ASCII characters are unprintable, these characters perform special functions such as a new line, back spacing etc.
Ø  The combination of backslash and these characters are called escape sequences.
Character Constant
Meaning
\n
New line (Line break)
\b
Backspace
\t
Horizontal Tab
\f
Form feed
\a
Alert (alerts a bell)
\r
Carriage Return
\v
Vertical Tab
\?
Question Mark
\'
Single Quote
\''
Double Quote
\\
Backslash
\0
Null








Basic concept for executing programs:
  • SAVE with  .c extension (in user directory)
  • COMPILE = F9
  • RUN = Ctrl+F9
  • O/P = Alt+F5 ( to shift control to output window )  

Execution of C Program:
C program executes in following 4 (four steps).

1)      Install:- install “C” software Turbo TC1,TC2
2)      Creating a program & saved: - create “C” program and saved as “file_name.c”, an extension.
Ø  File name can be any user define name.
3)      Compiling the program: The next step is to compile the program. The code is compiled by using compiler. Compiler converts executable code to binary code i.e. object code.
4)      Linking a program to library: The object code of a program is linked with libraries that are needed for execution of a program. The linker is used to link the program with libraries. It creates a file with '*.exe' extension.
5)      Execution of program: The final executable file is then run by dos command prompt or by any other software.

Compiler: -
Ø  Compiler is a special program used to convert source code (source file) into object code.
Ø  Compiler generates object code and stored it on secondary memory (hard disk).
Ø  Object code is collection of zeros (0) and ones (1).
Linker:-
Ø  Linker is a special program used to convert assembly language instruction into machine level language instruction.
Ø  These instructions will be executed by processor with the help of operating system and gives the output\ result.

Small program of “C”:-    #include<stdio.h>
                                      void main()


Source: From Google

No comments: