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

Recommended Answers

All 2 Replies

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;
}

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

Thanks again :)

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.