/** * Reads in a file from the specified input path and outputs a a binary decoding to * specified bin path and a fully decoded version to specified output path. * This should simply open the necessary files, call the above helper functions * in the correct sequence, and close the necessary files. * * @param input the path to the input file * @param bin the path to the decoded ASCII binary output file * @param output the path to the decoded output file * @param index The index of the bit from which binary values should be extracted */ void decodeFile(char* input, char* bin, char* output, int index){ FILE* in,*binary,*out; in=fopen(input,"r"); binary=fopen(bin,"r+w"); out=fopen(output,"w"); codeToBinary(in,binary,index); binaryToText(binary,out); fclose(in); fclose(out); fclose(binary); }
/** * Reads in a file from the specified input path and outputs a a binary decoding to * specified bin path and a fully decoded version to specified output path. * This should simply open the necessary files, call the above helper functions * in the correct sequence, and close the necessary files. * * @param input the path to the input file * @param bin the path to the decoded ASCII binary output file * @param output the path to the decoded output file * @param index The index of the bit from which binary values should be extracted */ void decodeFile(char* input, char* bin, char* output, int index){ //if the input array or bin array or output array is null, end function if(input == NULL || bin == NULL || output == NULL) { return; } //open the in file in read mode FILE *in = fopen(input, "r"); //open the binary file in write mode FILE *binary = fopen(bin, "w"); //if in or binary file is null, means fopen fails, end the function if(in == NULL || binary == NULL) return; //translate the encoded message into the bianry file codeToBinary(in, binary, index); fclose(binary); //open binary file in read mode binary = fopen(bin, "r"); //open output file in write mode FILE *character = fopen(output, "w"); //if binary file or output file is null, means fopen fail, end function if(binary == NULL || character == NULL) return; //translate the binary message into deocded message binaryToText(binary, character); //close all files fclose(in); fclose(binary); fclose(character); }