Hi -
The way you detect "end of file" usually depends on the library you're using to read the data, not on some "sentinel" value in the file itself.
If you have a 'C' or C++ program using the standard library, you'd declare your input variable type "int" (even though you're reading "char" values from the file) and look for the "special value" EOF (#define'd in <stdio.h>).
Here's an example:
Code:
#include <stdio.h>
#include <errno.h>
int
main (int argc, char *argv[])
{
FILE *fp = NULL;
int c; /* NOTE: even though we're reading "char", we
need to declare an "int" in order to detect EOF */
/* Check command line usage */
if (argc < 2)
{
printf ("USAGE: %s <filename>!\n", argv[0]);
return 1;
}
/* Open file */
fp = fopen (argv[1], "r");
if (fp == NULL)
{
printf ("ERROR: Could not open file %s, errno %d\n", argv[0], errno);
return 1;
}
/* Read file until EOF */
while ( (c = getc (fp)) != EOF)
{
printf ("char: %c:0x%02x\n", c, c);
}
/* Close file */
fclose (fp);
printf ("Done reading %s.\n", argv[0]);
return 0;
}
'Hope that helps .. PSM