Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!hellgate.utah.edu!cs.utexas.edu!wuarchive!usc!ucsd!ucsdhub!hp-sdd!hp-pcd!hpcvia!brianh From: brianh@hpcvia.CV.HP.COM (brian_helterline) Newsgroups: comp.lang.c Subject: HELP with stdprn in BINARY Message-ID: <18060005@hpcvia.CV.HP.COM> Date: 13 Dec 89 16:52:49 GMT Organization: Hewlett-Packard Co., Corvallis, Oregon Lines: 74 I have a problem using stdprn in binary mode with MSC 5.1 I set everything up and start printing the file, but the fwrite ends up bombing out. Is the code wrong? Has anyone experienced this? I changed to using _bios_printer() and it worked fine. If I print to a file rather than stdprn, the program works also. WHY?????? Any comments are welcome. AdvTHANKSance Brian /******************************************************************/ /* MS-C 5.1 */ #include #include #include #include #define BUF_SIZE 8196 char ReadBuf[BUF_SIZE]; int main(int argc, char **argv) { FILE *File; int n, nbytes; /* * Set stdprn to binary to avoid unwanted LF->CR-LF translation */ n = setmode(fileno(stdprn),O_BINARY); if( n == -1 ) { fprintf( stderr, "Can't change mode of stdprn\n" ); exit( 1 ); } File = fopen(argv[1], "rb"); if( File == NULL ) { fprintf( stderr, "Can't open %s\n", argv[1] ); exit( 1 ); } printf("Downloading\n"); while( (n=fread(ReadBuf, sizeof(char), BUF_SIZE, File)) == BUF_SIZE ) { nbytes = fwrite(ReadBuf, sizeof(char), BUF_SIZE, stdprn ); if( nbytes != BUF_SIZE ) { fprintf(stderr,"Write failure, %d != %d\n", nbytes, BUF_SIZE); exit( 1 ); } } if( ferror( File ) ) { fprintf( stderr, "Error occured while downloading"); exit( 1 ); } else { nbytes = fwrite(ReadBuf, sizeof(char), n, stdprn ); if( nbytes != n ) { fprintf( stderr, "Write failure, %d != %d\n", nbytes, n ); exit( 1 ); } } (void) fclose( File ); exit(0); }