Trying to read data from file into array...

...the code I am working with is below. The cout statement inside the while prints the appropriate character to the screen fine, but the myData[i] = ch statement doesn't seem to write the character to the array elements. If I try and do something like cout << myData[0]; after the while loop, it prints out junk. Any info appreciated...

int main ()
{
int i = 0;
const int SIZE = 260;
char myData[SIZE];
char ch;
fstream file;

file.open("data.txt", ios::in);
file.get(ch);
while(!file.eof())
{
int i=0;
myData[i] = ch;
file.get(ch);
cout << myData[i] << endl;
i++;
}
Very bad that you do int i=0; in the cycle. You always change the 0-th element.
...thanx melkiy...amazing how you just can't see a problem like that...
Topic archived. No new replies allowed.