Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Input and Output in C

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 51
    Comment on it

    In C programming we take input and print result based on that or whatever we want to .

     

    For doing input or output process C library has provided functions for doing it.

     

    Standard File File Pointer Device
    Standard input stdin Keyboard
    Standard output stdout Screen
    Standard error stderr Your screen

     

    The getchar() and putchar() Functions

     

    The getchar function is used to take characters from the string one by one by loop iteration.

     

    The putchar function is used to display string in the form of characters one by one by using loop iteration

     

    #include <stdio.h>
    int main( ) {
    
       int c;
    
       printf( "Enter a value :");
       c = getchar( );
    
       printf( "\nYou entered: ");
       putchar( c );
    
       return 0;
    }

     

     

    The gets() and puts() Functions

     

    The gets function is used to take input from the keyboard in string format.

     

    The puts function is used to display string.

     

    #include <stdio.h>
    int main( ) {
    
       char str[100];
    
       printf( "Enter a value :");
       gets( str );
    
       printf( "\nYou entered: ");
       puts( str );
    
       return 0;
    }

     

     

    The scanf() and printf() Functions

     

    The scanf function is used to take input from the user.

     

    The printf function is used to display output by the program or to the user

     

    #include <stdio.h>
    int main( ) {
    
       char str[100];
       int i;
    
       printf( "Enter a value :");
       scanf("%s %d", str, &i);
    
       printf( "\nYou entered: %s %d ", str, i);
    
       return 0;
    }

     

    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: