-
Use '\ n' in scanf () shield the carriage return.
Scanf ( " % D \ n- " , & n-); // use '\ n' Enter filter Scanf ( " % C " , & C);
or
scanf("%d",&x); scanf("\n%c",&c);
-
In scanf () format string front add a space, a carriage return character mask
Scanf ( " % D " , & n-); Scanf ( " % c " , & c); // % c front spaces, carriage returns filtered
-
Before receiving the characters, using getchar () to read a carriage return symbol
Scanf ( " % D " , & n-); getchar (); // dedicated to reading the last symbol entered the transport Scanf ( " % C " , & C);
-
Before receiving characters using fflush () Clear the contents of the input stream buffer
Scanf ( " % D " , & n-) fflush (stdin); // flush character input stream buffer, attention must be introduced #include <stdlib.h> header Scanf ( " % C " , & C);
c language input single characters are four ways to avoid carriage returns
Guess you like
Origin www.cnblogs.com/Theo-sblogs/p/11461507.html
Recommended
Ranking