/************************************** * RUN LENGTH DECODER FOR ASCII TEXT * * Code Copyright 2000 * * Jonathan Sapan '03 * * (unless noted otherwise) * **************************************/ #include #include FILE *inputFile; FILE *outputFile; main(int argc, char *argv[]) { int j; char a, b, i; char sentinel; inputFile = fopen(argv[1], "rb"); outputFile = fopen(argv[2], "w"); /*--------------------------------------------------------------------*/ if ( argc != 3 ) /*Check to see if program was called properly*/ { fprintf(stdout, "TOO FEW ARGUMENTS\n" ); exit(EXIT_SUCCESS); } /*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/ if ( (inputFile == NULL) || (outputFile == NULL) ) { fprintf(stdout, "INVALID FILE SPECIFIED\n"); exit(EXIT_SUCCESS); } /*--------------------------------------------------------------------*/ fread( &sentinel, 1, 1, inputFile ); while(1) { if ( fread( &a, 1, 1, inputFile) == 0 ) break; if ( a == sentinel ) { fread( &b, 1, 1, inputFile); fread( &i, 1, 1, inputFile ); for ( j = 0; j < i + 4; j++ ) fprintf(outputFile, "%c", b ); } else fprintf(outputFile, "%c", a ); } fclose(inputFile); fclose(outputFile); return 0; }