English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I intitialize an array of 100 elements of integer type which reads data from a file but file has only 10 elements what should be the condition of while statement that terminate after the 10th element
like
while(index<100 && ???)
plz help me

2007-04-11 03:02:17 · 4 answers · asked by sirf _tum 1 in Computers & Internet Programming & Design

4 answers

There are multiple ways to do this. Here are two ways:

1)

ifstream inFile;
int array[100];
index = 0;

inFile.open("file.txt");

while(index < 100 && inFile >> array[index])
{
index++;
}


2)

ifstream inFile;
int array[100];
index = 0;

inFile.open("file.txt");

while(index < 100 && !inFile.eof())
{
inFile >> array[index];
index++;
}

// I hope this helps

2007-04-11 10:22:25 · answer #1 · answered by Silver_Sword 3 · 0 0

FILE fp;


while(index<100 && feof(fp))

2007-04-11 03:12:34 · answer #2 · answered by iyiogrenci 6 · 0 0

NOT EOF

or maybe !EOF

2007-04-11 03:06:09 · answer #3 · answered by Anonymous · 0 0

why dont u use loop?

2007-04-11 03:23:22 · answer #4 · answered by expert m 1 · 0 1

fedest.com, questions and answers