Quick simple question
Ok, I feel like an idiot, but...
How can i read in from a file with a string of numbers and characters, and put each into it's corresponding type?
For example, let's say I have the following input file:
and I want to read in each number, the WHOLE number (i.e. 21, not 2, as the 1st num) into an int, but read in each non-space char in as a char. seems I can't use isdigit() as I won't get a whole number, just something below 9. :(
21 43 + 21 21 - - 92 *
getline() the whole line from the file. Make a function that gets the next token in your string (using space as your deliminater (look up strchr)). Make another function that checks to see if the token is an integer or not. If it is, put it into an integer variable, else put it in to a char or string value. repeat until all tokens have been read.
If you can get 1 digit at a time try this.
number = 0;
input = read from file
number = number * 10 + input;
input = read from file;
Ohh remember '1' is not the same as 1. You may need to convert from ASCII character to digit.