0

if you type "123e1" in the command line, the system may read "123" and save the value.

but how can we tell the computer that it's an wrong input?:-|

5
Contributors
6
Replies
7
Views
10 Years
Discussion Span
Last Post by WaltP
0

Read the input into a string, not a numerical variable. Then validate the string. Once validated convert the string into a numerical variable.

0

Lerner, he may be asking how to validate it.
If so you somewhat like this

BOOL IsNumber(char szString[])
{
   for(i = 0; szString[i] != 0; i++)
   {
      if(szString[i] >= '0' && szString[i] <= '9')
      {
         // This carachter is number.
      }
      else
         return FALSE;
         // This one ain't, your outta here.
   }
   return TRUE;
}
0

Lerner, he may be asking how to validate it.
If so you somewhat like this

BOOL IsNumber(char szString[])
{
   for(i = 0; szString[i] != 0; i++)
   {
      if(szString[i] >= '0' && szString[i] <= '9')
      {
         // This carachter is number.
      }
      else
         return FALSE;
         // This one ain't, your outta here.
   }
   return TRUE;
}

I don't think that would work.

0

I don't think that would work.

Why not?

Agree. If you're going to complain about something, the least you can do is give some kind of explanation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.