Problems reading in data correctly

Here is my task. I want to read in from a file a set of numbers, but I need to read them in as CHARS. I then need to convert each one to INTS. Each character will be stored in an array and then will be added together. The problem I am having is it seems that I keep reading in the '\n' and I dont want that. Here is my code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  
    char char1;
    int num1 = 0;
    int i = 0;


    while (char1 != '\n')
    {
        inFile.get(char1);
        num1 = char1 - '0';
        arr1[i] = num1;
        cout << arr1[i];
        i++;
    }
}


This is the output I get:

123456-38


It should be just 123456.

Can anyone point me in the correct direction?
You read the char at line 9, but you don't check it until the program loops back to line 7.

You also haven't initialized char1 to anything for that first loop.

Better to extract the data inside the while loop. Also, make sure that the file is in good condition:
 
while (inFile.get(char1) && char1 != '\n')
ughh.. such a simple fix..

Thanks LowestOne
Topic archived. No new replies allowed.