Xref: news2.mv.net comp.os.msdos.djgpp:8510 From: John Moon Newsgroups: comp.os.msdos.djgpp Subject: Binary files and ^C chars-try again Date: Wed, 11 Sep 1996 11:21:33 -0700 Organization: Naval Research Lab Lines: 63 Message-ID: <3237032D.258A@ccfsun.nrl.navy.mil> NNTP-Posting-Host: jamoon.nrl.navy.mil Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit CC: moon2 AT ccfsun DOT nrl DOT navy DOT mil To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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 #include #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); }