Guest_imported
New member
- Jan 1, 1970
- 0
I have written this routine for assigning the bytes of a (large) file to
an int type array and the loop is supposed to end at the end of file.
Unfortunately it exits the loop ( EOF is reached ), a lot more earlier
than the actual end of file! Here is the code of the routine:
/******************************************************************************
This function accepts a file and returns through the function the file
size and through an array the bytes of the file.
******************************************************************************/
int assign(FILE *fp, int bytes[])
{
int c, index = 0;
while ((c=getc(fp)) != EOF)
{
bytes[index] = c;
index++;
}
return index;
}
Any ideas why?
an int type array and the loop is supposed to end at the end of file.
Unfortunately it exits the loop ( EOF is reached ), a lot more earlier
than the actual end of file! Here is the code of the routine:
/******************************************************************************
This function accepts a file and returns through the function the file
size and through an array the bytes of the file.
******************************************************************************/
int assign(FILE *fp, int bytes[])
{
int c, index = 0;
while ((c=getc(fp)) != EOF)
{
bytes[index] = c;
index++;
}
return index;
}
Any ideas why?