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?:-|

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

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;
}
Member Avatar for iamthwee

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.

Why not?

Member Avatar for iamthwee

try it.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.