binary to ascii
Siva Chelliah
siva at bally.Bally.COM
Fri Sep 14 16:09:25 AEST 1990
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 <sys/types.h>
#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);
}
}
More information about the Comp.lang.c
mailing list