I'm using getline to grab lines from an input data file that looks like this
1 9
5 5
6 7
...
Where the first number the number of siblings someone has and the second number is someone's age.
const int MAXLINE=50;
int main(int argc, char *argv[]) {
int numberOfSiblings;
int age;
char oneline[MAXLINE];
ifstream inputData;
inputData.open(argv[1]);
while ( !(inputData.eof()) ) {
inputData.getline(oneline, MAXLINE);
numberOfSiblings = oneline[0] - '0';
age = oneline[2]-'0';
}
}
Howerver, I can't assume that those ints will always be at the same index due to white space.
Since if there are two spaces rather than one age will now be in index 3. How can I account for this?
Also, what happens if I have a double digit number?