Home > Back-end >  C language of getchar ()
C language of getchar ()

Time:10-28

Why when y is type int the scanf () behind to add two getchar (), if not add getchar (), at the back of the data values will be equal to y; Add a getchar (), the value of the data as \ n;
When y for char type the scanf () the back to add a getchar (), if not add getchar (), at the back of the data values will be equal to \ n;

# include & lt; Stdio. H>
# define M 3
Int main ()
{
Char a, [M].
char data;
Int I, y.
int j=0;

Printf (" please enter: ");
For (I=0; i {
The scanf (" % c ", & amp; A [I]);
getchar();
}

Printf (" result is: ");
For (I=0; i {
Printf (" % c ", a [I]);
}
printf("\n");

Printf (" ha ha ha ");
The scanf (" % d ", & amp; Y);
//getchar ();
//getchar ();
Printf (" please input to query letters: ");
The scanf (" % c ", & amp; The data);
While (data!=a [j])
{
j++;
}

Printf (" is: % d ", j);
getchar();
getchar();
return 0;
}
  • Related