/* reads a datafile in ASCII and saves it in binary format */ /* adding .bin to the filename given on the command line */ #include #include #include FILE *binary; FILE *ascii; main(int argc, char *argv[]) { int in, status; char tmp[50]; ascii=fopen(argv[1], "r"); if (ascii==NULL) { printf("\ninput file does not exist - program stopped\n\n"); exit(status); } strcpy(tmp, argv[1]); strcat(tmp, ".bin"); /* add .bin to output filename */ binary=fopen(tmp, "w"); /* open output file */ while (fscanf(ascii, "%d", &in)>0) /* read until end of file or error */ { fputc(in, binary); /* write as binary */ } fclose(ascii); fclose(binary); }