Reading from standard input and writing characters and strings to standard output using scanf()/scanf_s() and printf() C functions
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 from standard input and writing characters and strings to standard output using scanf()/scanf_s() and printf() C functions
To show: How to read from standard input and write to standard output, characters and strings using scanf()/scanf_s() and printf() C functions
// Reading characters and strings
#include <stdio.h>
int main(void)
{
char x = 'a', y[20];
printf("Enter a string (max 19): ");
/* scanf("%c%s", &x, y); */
/* read a character and then a string */
scanf_s("%c%s", &x, 1, y, 20);
printf("The input was: \n");
printf("the character \"%c\" ", x);
printf("and the string \"%s\"\n", y);
return 0;
}
Output example:
Enter a string (max 19): Thisismystring!
The input was:
the character "T" and the string "hisismystring!"
Press any key to continue . . .