Reading the input data with a several field widths using scanf()/scanf_s() C function

 

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C Code (/TC)

Other info: none

To do: Reading the input data with a several field widths using scanf()/scanf_s() C function

To show: How to read input data into several different field widths using scanf()/scanf_s() C function

 

 

// Input data with a field widths

#include <stdio.h>

 

int main(void)

{

int x, y;

 

printf("Enter a six digit integer: ");

/* scanf("%2d%d", &x, &y); */

/* read two digits, and then the rest */

scanf_s("%2d%d", &x, &y);

printf("The integers input were %d and %d\n", x, y);

 

return 0;

}

 

Output example:

 

Enter a six digit integer: 732956

The integers input were 73 and 2956

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index