Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How can c language only allow numbers to be input into scanf?
How can c language only allow numbers to be input into scanf?
Scanf () returns the number of correctly read data.

For example, three data x, f, d,

If the return value is not equal to 3, Scanf requires re-entry.

# include & ltstdio.h & gt

# include & ltstdlib.h & gt

Master ()

{

int x;

Floating f;

Double d;

while ( scanf("%d %f %lf ",& ampx & amp; f & amp; d)! = 3) {

Printf ("Error, please enter int float double each again! \ n ");

fflush(stdin);

}

printf("good: %d %f %lf\n ",x,f,d);

Returns 0;

}