My objective is to check to see if a number is odd or even and print it to the screen just to make sure its working correctly.
The data file contains:
138
402 2 485
9
43
98 805
58
421
948 7 97
48
67
35
42
948
579 39 12
700 20 500 210
98
I can get the numbers to print fine using:
1 2 3 4 5 6 7 8 9 10 11
|
ifstream infile1(argv[1]);
if(!infile1.is_open())
cout << "Could not open file";
else
{
char listNum;
while(infile1.get(listNum))
cout << listNum;
}
|
However, when I check for odd or even numbers it will check each and every number.
printed like this (partial list):
1 is odd 3 is odd 8 is even
9 is odd
But it should print:
138 is even
9 is odd
I tried using getline, but it keeps giving me the errors:
invalid conversion from 'void*' to 'char**'
invalid conversion from 'char' to 'size_t*'
too few arguments to function 'ssize_t getline(char**, size_t*, FILE*)'
Here is the getline code, what am I doing wrong? I have tried switching things around, adding things. Just nothing works.
1 2 3 4 5 6 7 8 9 10
|
ifstream infile1(argv[1]);
if(!infile1.is_open())
cout << "Could not open file";
else
{
char listNum;
getline(infile1, listNum);
cout << listNum;
}
|