C : DATA INPUT AND OUTPUT

DATA INPUT AND OUTPUT

DATA INPUT AND OUTPUT



SINGLE CHARACTER INPUT AND OUTPUT :


  1. getchar() :

    1. The getchar() function is used to get a single character from the user.

    2. At a time it reads only a single character,so if we have entered character say 'xyz' it will only take 'x' as a single character.

    3. SYNTAX : char variable_name = getchar();

  2. putchar() :

    1. The putchar() function is used to print/display the single character that user have entered using getchar() function.

    2. The function will display only a single character at a time.

    3. SYNTAX : putchar(variable_name);


  

#include <stdio.h>

void main()
{
  char a;
  a=getchar();
  putchar(a);
}




SCANF AND PRINTF FUNCTION :

  1. scanf() :

    1. The scanf() function is used to get input of any datatype from the user.

    2. It scans/take input from the user according to the format provided.

    3. Format specifies the datatypes such as %d,%s,%c,%f for integer,string,character,float.

    4. SYNTAX : scanf("format",&variable_name);;

  2. printf() :

    1. The printf() function is used to print/display string along with the values if required.

    2. It is used for guiding the user and also to print the values/data.

    3. SYNTAX : printf("control string format"variable_name);




  

#include <stdio.h>

void main()
{
  int num;
  printf("ENTER NUMBER : ");
  scanf("%d",&num);
  printf("\nTHE NUMBER YOU HAVE ENTERED IS : %d",num);
}





GETS and PUTS function :

  1. gets() :

    1. This function is useful to accept from the keyboard and store it into a variable.

    2. SYNTAX : gets(str);

  2. puts() :

    1. This function displays a string on the monitor.

    2. SYNTAX : puts(str);

Comments