question about recognizing data

V

vamp4l

my program reads in data separated by whitespace, but i cant figure out
how to test for what kind of data it is.
for example the input is:

y = 16 ;

it takes each piece of data in as string type, and it needs to tell
what kind of data it is...so for when it reads in the value '16' how
can i get my program to determine that it is an integer or if the value
was 16.123 how could it recognize it as a float?

ive tried something like converting it using atoi or atof but that
doesnt seem to be the right method.

any help is appreciated
 
V

Victor Bazarov

vamp4l said:
my program reads in data separated by whitespace, but i cant figure
out how to test for what kind of data it is.
for example the input is:

y = 16 ;

it takes each piece of data in as string type, and it needs to tell
what kind of data it is...so for when it reads in the value '16' how
can i get my program to determine that it is an integer

There seems no dot after it...
or if the
value was 16.123 how could it recognize it as a float?

Try to treat it as a float. If you get it, it's a float.
ive tried something like converting it using atoi or atof but that
doesnt seem to be the right method.

'atoi' and 'atof' are a bad idea. Try 'strtod' and 'strtof'. RTFM about
them carefully, they allow you to check conversion errors.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,800
Messages
2,569,657
Members
45,415
Latest member
KarolDicke
Top