Hi all. I am beginner in C. My question is: What is " \n" inside scanf()?
Here is part of the implementation of an example:
...
char myChar;
int myID;
scanf("%c", &myChar);
scanf("%d\n"; &myID);
printf("Option: %c, ID: %d\n", myChar, ID);
...
The reason that I break scanf() into 2 parts is that I need to take either one argument or two arguments from ONE input line depending on what the first argument is. The following is the input line:
a
(or)
b 120
*a -- I only need one argument.
*b -- I need two arguments; the second argument is the ID.
The problem is my program still asking for the next input line before the results are printed. How I can fix it? Thanks.
Here is part of the implementation of an example:
...
char myChar;
int myID;
scanf("%c", &myChar);
scanf("%d\n"; &myID);
printf("Option: %c, ID: %d\n", myChar, ID);
...
The reason that I break scanf() into 2 parts is that I need to take either one argument or two arguments from ONE input line depending on what the first argument is. The following is the input line:
a
(or)
b 120
*a -- I only need one argument.
*b -- I need two arguments; the second argument is the ID.
The problem is my program still asking for the next input line before the results are printed. How I can fix it? Thanks.
Comment