| PLEX86 | ||
|
Newbie Q: Interactive program eats up CPUSteve Kirkendall Thank you, steve. I read some faq and they all say I should avoid scanf. Right now, my code is below: char mstr6; ...... if (fgets(mstr, sizeof mstr, stdin) == NULL) break; printf("%s-n", mstr);* for debugging * input = atoi(mstr); { printf("%d: input error, must be a number between 1000 and 9999!-n",input); continue;* goto loop start * } ...... If my input is longer than 4, either digits or letters, which will show the error after atoi. But next fgets is skipped and error message is show again, which is like scanf somewhat. For instance, I type abcdefghijklmnopq and enter, I get: Kmail problems with filters and Spam 7178 From my Kmail filter rules:- Filter named 'Bogofilter Check': under 'Filter Criteria' is 'match all of 'Filter Actions... Input a 4-digit number:abcdefghijklmnopq abcde 0: input error, must be a number between 1000 and 9999! Input a 4-digit number:fghij 0: input error, must be a number between 1000 and 9999! Input a 4-digit number:klmno 0: input error, must be a number between 1000 and 9999! Input a 4-digit number:pq I read somewhere says fgets stops when reading size-1 characters or when it encouters EOF, but the result above shows fgets read my whole line to the mstr. And mstr is only 6 bytes long, where is the rest of the line stored? Maybe the memory after mstr, which is unknow to the program and me. Can that be called a buffer overflow? Is it still dangerous? I want my program only shows the error message one time one input, however long the input is. Can I manage?-bow
|
||||
Kmail problems with filters and Spam 7178 Linux groups from Newsgroups The #1 Usenet Provider on the Internet
|
||||