Mail Archives: djgpp/1996/09/11/17:19:18
Let's try this again,
This may be a dumb question, but
when I try to read a ^C char in binary from a
file I get an EOF condition, no matter if I try
to read further into the file or not. Is this a
perversity of the djgpp stdlib? If so, what is the
standard work-around? I have tried getc, fgetc,
fscanf, and fread, and they all do the same thing.
Apparently, the 255 (EOF) char does the same thing so
even if I get the file size and fseek past the
offending character I don't know whether it was a
^C or EOF.
I am using go32 v 1.12.maint3
Thanks for dispelling my ignorance,
John Moon
PS Here's the code-it's only a few lines
#include <stdio.h>
#include <math.h>
#define MAX 300
main(argc,argv)
int argc;
char *argv[];
{
FILE *fp,*fopen();
long i=0,lala;
int c,j;
char buf[255];
/* this creates a test binary file 0-255 named w/ contents of argv[1] */
if((fp=fopen(argv[1],"w"))!=NULL) {
for(i=0; i < 256; ++i) fputc((char)i,fp);
fclose(fp);
}
/* this attempts to read it back */
if((fp=fopen(argv[1],"r"))!=NULL) {
fseek(fp,0L,SEEK_END);
lala=ftell(fp);
printf("\n\n\nFile Size = %ld\n",lala);
rewind(fp);
for(i=0; i < MAX; ++i) {
j=fread(buf,(size_t)1,(size_t)1,fp);
printf("%ld %d %d",i,j,buf[0]);
printf("\n");
}
}
else fprintf(stderr,"cant open %s\n",argv[1]);
exit(0);
}
- Raw text -