next up previous contents index
Next: Command line arguments Up: Input/Output Previous: Input/Output   Contents   Index


Standard Input/Output/Error

We have already seen in earlier examples how to print something out to the screen (standard output):
  printf("How are you?");
as well as formatted statements:
  age = 22;
  printf("You are %d years old", age);

To get user input, the scanf statement can be used to get input from standard input::

  int age;
  printf("How old are you?");
  scanf("%d", &age);
  printf("You are %d years old", age);
The first argument is the format string detailing in what format the input is to be expected, while the second argument is the variiable list to be assigned to that input. Note the use of the address of operator & - the meaning of this will be discussed when we come to pointers in C.