scanf之變數參數

type Qualifying Input  
c Single character: Reads the next character. If a width different from 1 is specified, the function reads width characters and stores them in the successive locations of the array passed as argument. No null character is appended at the end.  
d Decimal integer: Number optionally preceded with a + or - sign.  
e,E,f,g,G Floating point: Decimal number containing a decimal point, optionally preceded by a + or - sign and optionally folowed by the e or E character and a decimal number. Two examples of valid entries are -732.103 and 7.12e4  
o Octal integer.  
s String of characters. This will read subsequent characters until a whitespace is found (whitespace characters are considered to be blank, newline and tab).  
u Unsigned decimal integer.  
x,X Hexadecimal integer.

【範例】

/* printf example */

#include <stdio.h>
#include<stdlib.h>

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

  printf ("Enter your family name: ");
  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);
  system("PAUSE");
  return 0;
}

執行結果:
Enter your family name: Soulie
Enter your age: 29
Mr. Soulie , 29 years old.
Enter a hexadecimal number: ff
You have entered 0xff (255).