0

Hi.. How do I check the data type in an input file ?

Suppose my text file looks like this. Tab separated :-

123   456   ABCD
789   890   EFGH
298   764   IUHJ

Now I read the file like char or string in my while loop using getline. So how do I cross check that suppose the first field is integer or not. 3rd field is a string if not pop up an error. Maybe its better to cross check it separately before reading the file.

Any idea ?

Thanks

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Web_Sailor
0

write your own functions for validation.
e.g.

bool isnum(char *str)
{
       if(str==NULL)
            return false;
       while(*str)
       {
           if(!isdigit(*str))
                  return false;
           str++;
       }
        return true;
}
0

Great example .. Thanks :)
Very helpful.. I have marked solved but will come back if I get some questions.

Thanks again :)

This question has already been answered. 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.