scanf
int  scanf ( const char * format [ , argument , ...] );
stdio.h
  cplusplus.com  

Read formatted data from stdin.
  Reads data from the standard input (stdin) and stores it into the locations given by argument(s). Locations pointed by each argument are filled with their corresponding type of value requested in the format string.
  There must be the same number of type specifiers in format string than arguments passed.

Parameters.

format
String that can contain one or more of these items:
argument(s)
pointer to objects or structures to be filled with data read as specified by format string. There must be the same number of these parameters than the number of format tags.
NOTE: These arguments must be pointers: if you want to store the result of a scanf operation on a standard variable you should precede it with the reference operator, i.e. an ampersand sign (&), like in:
int n;
scanf ("%d",&n);

Return Value.
  The number of items succesfully read. This count doesn't include any ignored fields with asterisks (*).
  If EOF is returned an error has occurred before the first assignation could be done.

Portability.
  Defined in ANSI-C.

Example.

/* scanf example */
#include <stdio.h>

main ()
{
  char str [80];
  int i;

  printf ("Enter your surname: ");
  scanf ("%s",str);  
  printf ("Enter your age: ");
  scanf ("%d",&i);
  printf ("Mr. %s , %d years old.\n",str,i);
  printf ("Enter a hexadecimal number: ");
  scanf ("%x",&i);
  printf ("You have entered %#x (%d).\n",i,i);
  
  return 0;
}
This example demonstrates some of the types that can be read with scanf:
Enter your surname: Soulie
Enter your age: 23
Mr. Soulie , 23 years old.
Enter a hexadecimal number: ff
You have entered 0xff (255).

See also.
  fscanf, printf, fopen, fclose


© The C++ Resources Network, 2000