Hi here is my problem im adding to a program to catch errors.The program below catches errors like integers less than 0 or not equal to 1 but if I put in a number like 223e it doesn't catch the e as an error I know I am missing something in my error = sscanf() line but cant figure it out please help. -
char line[MAXLINE];
-
int error, n;
-
-
do{
-
printf("Input a positive integer: ");
-
fgets(line, MAXLINE, stdin);
-
error = sscanf(line, "%d", &n) != 1 || n<= 0;
-
if (error)
-
printf("\nError: Do it again. \n");
-
} while (error);
-
-
2 1237
sscanf parses the input string until it reaches the end of the format string or the end of the input string. In your example you cite, the format string ends first. You want to verify that sscanf reached the end of the input string. Take a look at the %n conversion specifier.
Does your program properly handle leading and trailing whitespace?
the program does handle whitespace correctly.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Agnes |
last post by:
I create an object named Number , with the function numtowords.
i input '100' as parameter, It will return "one hundred".
However, any simple way to test this object ????
I only know the old way ...
|
by: Alexei A. Frounze |
last post by:
Seems like, to make sure that a pointer doesn't point to an object/function,
NULL (or simply 0) is good enough for both kind of pointers, data pointers
and function pointers as per 6.3.2.3:
3 An...
|
by: Tim |
last post by:
Dear All,
I have discovered, to my dismay, that the ShowDialog function will not
function correctly when used with the AnimateWindow API. The owned
form is opened behind the owning form on the...
|
by: Agnes |
last post by:
I create an object named Number , with the function numtowords.
i input '100' as parameter, It will return "one hundred".
However, any simple way to test this object ????
I only know the old way ...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |