reading a file into an array

Hi,

I am new to this. I am trying to create a c++ program that can read in numbers from a file.

my file looks like this.
3 4 5 6 0
4 5 9 8 1

I am suppose to input each line of numbers into two seperate arrays of size 30.Any other array space that is not filled up, i am suppose to put in a zero.
so one of my array will include {3,4,5,6,0,0,0,0...} etc. Same with the other array.

can anyone please help?


void produceNum (int x[30], int y[30])
{
char ch = 'a';
int i = 0;
ifstream ins;
ins.open(in_file);
while (ch != '\n')
{
ins >> x[i];
ins.get(ch);
i++;
}
while (ch !='\n')
{
ins >> y[i];
ins.get(ch);
i++;
}
ins.close();



Last edited on
Post your code and we can help, otherwise we don't do homework assignments.
I think is best if you don't use ins.get(ch) but ins.peek() in the condition, the resulting loop should be somthing like:
1
2
while ( ins.peek() != '\n')
    ins >> x[i++];
(this is supposed to receive correct input, it doesn't check it)
Topic archived. No new replies allowed.