Home > Back-end >  Why can't this code in force
Why can't this code in force

Time:12-30

#include
Int num [8].
Int main ()
{
int a;
Int b;
Int c;
Printf (" Are you sure? (Any number to continue) ");
While (the scanf (" % d ", & amp; C)==1)
{
Printf (" Enter num ");
For (a=0; A==7; +);
{
Num [a]=getchar ();
}
For (b=7; B==0; B -);
{
Printf (" % d ", num [b]);
}
Printf (" Are you sure? (Any number to continue) ");
}
return 0;
}
The results are as follows:
Are you sure? (Any number to continue) 5
Enter num0Are you sure? (Any number to continue)
Expected to order type array contents, printed in reverse chronological order

CodePudding user response:

For end-of-line have extra semicolon

CodePudding user response:

To search the getchar () function usage, modified as follows, for reference:
 # include & lt; stdio.h> 

Char num [8].//int num [8].

Int main ()
{
int a;
Int b;
Int c;
Printf (" Are you sure? (Any number to continue) ");
While (~ the scanf (" % d ", & amp; C))//while the scanf (" % d ", & amp; C)==1)
{
If (c & lt; 1) break;
getchar();
a=0;
Printf (" Enter num: \ n ");
//for (a=0; A==7; +);
//{
While ((num [a]=getchar ())!='\ n' & amp; & A<8) +;

Num [a]='\ 0';

//}
//for (b=7; B==0; B -);
//{
Printf (" % s \ n ", num);//printf (" % d ", num [b]);
//}
Printf (" Are you sure? (Any number to continue) ");
getchar();
}

return 0;
}
  • Related