Path: utzoo!censor!becker!hybrid!scifi!bywater!uunet!bally!siva From: siva@bally.Bally.COM (Siva Chelliah) Newsgroups: comp.lang.c Subject: binary to ascii Keywords: binary, ascii, translation Message-ID: <371@bally.Bally.COM> Date: 14 Sep 90 06:09:25 GMT Distribution: usa Organization: Bally Mfg. - Reno, Nevada Lines: 35 I wrote a program to translate binary files to ascii. I tried under Microsoft C 5.1 and Turbo C 2.0. But it works with some files and stops in the middle of some files. When I ran it against itself after compiling with Microsoft C, it stopped when it tried to read 1A Am I missing something? Please help. Now I know there is a program in UNIX to do this (uuencode) If anybody wants the other program (ascii to binary ) let me know. Of course, we have to fix this first. NOTE : both programs works fine under UNIX. #include "stdio.h" #include #include "unistd.h" #include "fcntl.h" main (argc,argv) int argc; char *argv[]; { unsigned int i; int hl; long flen; char c; FILE *fp; if((hl=open(argv[1],O_RDONLY))==-1){ printf("error : file not found "); exit(1); } while (read(hl,&c,1)==1){ i=(int ) c; i=i & 0x00FF; /* this is necessary because when you read, sign is extended in c */ printf("%02X",i); } }