Home > Back-end >  Beginners ask a very simple C language problem
Beginners ask a very simple C language problem

Time:04-11

I am beginner C language in the book a few days don't quite understand the following

This topic I choose two, and then use the computer then I want to try to output the x, y, a, b, c is the result of how, but every time I play the output code will appear a mistake, delete output that line of code is zero error, so I have two questions ask you: 1. Can you list this question correct output code let me consider, I am really not, 2. Saying this again with the scanf input with getchar input again, when the operation box assignment is to give them the assignment? Has been very confused this question,

Thank you thank you

CodePudding user response:

Should choose four procedures section, enter the number 1 2 followed by a carriage return, is retained in the buffer, the carriage return is not what we want, so four procedures section use & amp; A read one more time, the scanf () detailed usage can explain online search related material, for reference:
 # include 

Int main ()
{
Int x, y;
Char a, b, c;

The scanf (" % d % d % % % % c c c c ", & amp; X, & amp; Y, & amp; A, & amp; A, & amp; B, & amp; C);
//a=getchar ();
//b=getchar ();
//c=getchar ();
Printf (" x=% d, y=% d, b=% c, c, b=% % c=c ", x, y, a, b, c);

return 0;
}

//run:

//1 2
//ABC
//x=1, y=2, a=a, b=b, c=c please press any key to continue...

CodePudding user response:

reference 1st floor QZJHJXJ response:
should choose four procedures section, because the input Numbers 1 2 followed by a carriage return, is retained in the buffer, the carriage return is not what we want, so four procedures section use & amp; A read one more time, the scanf () detailed usage can explain online search related material, for reference:
 # include 

Int main ()
{
Int x, y;
Char a, b, c;

The scanf (" % d % d % % % % c c c c ", & amp; X, & amp; Y, & amp; A, & amp; A, & amp; B, & amp; C);
//a=getchar ();
//b=getchar ();
//c=getchar ();
Printf (" x=% d, y=% d, b=% c, c, b=% % c=c ", x, y, a, b, c);

return 0;
}

//run:

//1 2
//ABC
//x=1, y=2, a=a, b=b, c=c please press any key to continue...

thank thank??
  • Related