Integer error C -
this question has answer here:
- how check if input numeric in c++ 7 answers
this have now:
int main() { int number; printf("type number: "); scanf("%i",&number); char code[4]; printf("type code: "); scanf("%s",&code);
when type numbers in first 1 script goes crazy, shows
type number: notanumber
type code: therestofthescript
-- command line
what want is
type number: notanumber
you didn't enter number
-- command line
how can this?
this different said duplicate. i'm talking c here, not c++. c doesn't know cin
, answer said duplicate. however, answer found below
for input string use
scanf("%s",code);
or better
scanf("%3s",code);
to check correct input number use value returned scanf:
char ch; if( 1 == scanf("%i",&number) ) { // use correct number } else { // clean input bufer while( (ch = getchar()) != '\n' && ch != eof); }
Comments
Post a Comment