Question: Urgent! Need Help ASAP with this C Programming Assignment. I need to turn this in tomorrow night For this lab, you are going to create
Urgent! Need Help ASAP with this C Programming Assignment. I need to turn this in tomorrow night
For this lab, you are going to create two programs. The first program (named AsciiToBinary) will read data from an ASCII file and save the data to a new file in a binary format. The second program (named BinaryToAscii) will read data from a binary file and save the data to a new file in ASCII format. Background Preparation:
Review file I/O for ASCII and binary formats, including the fread(), fwrite() and fprintf() functions.
Review your notes on Command Line Parameters and/or find information online at a site such as https://www.tutorialspoint.com/cprogramming/c_command_line_arguments.htm
Specifications: Both programs will obtain the filenames to be read and written from command line parameters. For example:
bash$ AsciiToBinary ascii_in binary_out bash$ BinaryToAscii binary_in ascii_out
The data contained in the ASCII file (both reading from and writing to) will be 10 floating point numbers, 10 lines of text, and 10 signed integers. There will be only one data item per line, and each line of text will contain no more than 40 characters (including ' ' and the NULL terminator). The data contained in the binary file (both reading from and writing to) will be 10 floating point numbers (of type double), 400 characters, 10 signed integers. You may find it helpful to think of the 400 characters as 10 lines of 40 characters each. When writing the floating point values to the ASCII output file, write them to four decimal places.
Sample ASCII and binary format files are provided. The data in the two files correspond to each other. There will be no blank lines found in either file. The specific method that you use to read and write the data is up to you. You may wish to read all the data from the input file before writing to the output file, or you may wish to write each data element as it is read. Be sure to close both files (input and output) before exiting the program. Compiling: Your programs should both compile using a single Makefile (i.e. the make command will compile both programs). Therefore, your Makefile will have at least four targets - all (which will be the uppermost target in the file), AsciiToBinary, BinaryToAscii, and clean (the last target in the file). The executable names do not need to conform to the standard naming conventions used for CS262. However, all directories and source files do need to adhere to these standards. Testing: Besides testing your code with your usual methods, you should also test your programs by reading an ASCII file, converting it to binary, then reading the binary file and converting it to ASCII. The new ASCII file should match exactly with the original ASCII file.
Where you can download files:
acsii_file.txt
https://www.dropbox.com/s/bwy86vpyozgq9xn/ascii_file.txt?dl=0
binary_file.bin
https://www.dropbox.com/s/5cujl5vob4ns1wf/binary_file.bin?dl=0
Please answer this question as soon as possible
Here is what I have so far
AsciiToBinary
#include #include int main(int argc, char *argv[]) { FILE *infile = fopen(argv[1],"r"); FILE *outfile = fopen(argv[2],"wb"); int status; int num; //char line = ' '; if(infile == NULL) { printf("File Not Found "); exit(0); } char s[100]; while(fgets(s,100,infile)) { fwrite(s,sizeof(s),1,outfile); //printf("ASCII to binary conversion is done "); } fclose(infile); fclose(outfile); printf("ASCII to binary conversion is done "); return 0; }
BinaryToAscii.c
#include #include int main(int argc, char *argv[]) { if ( argc != 3 ) { fprintf(stderr, "You need two arguments. "); return EXIT_FAILURE; } FILE * infile = fopen(argv[1], "rb"); if ( !infile ) { fprintf(stderr, "Couldn't open file: %s ", argv[1]); return EXIT_FAILURE; } FILE * outfile = fopen(argv[2], "w"); if ( !outfile ) { fprintf(stderr, "Couldn't open file: %s ", argv[2]); return EXIT_FAILURE; } char s[100]; int num; while(1) { fscanf(infile,"%s",s); fprintf(outfile,"%s",s);
}
fclose(infile); fclose(outfile); return 0; }
And Also:
For this lab, you are going to modify the two programs you created for Lab 7 (copy them to a new directory first!). Like in Lab 7, the first program (named AsciiToBinary) will read data from an ASCII file and save the data to a new file in a binary format. The second program (named BinaryToAscii) will read data from a binary file and save the data to a new file in ASCII format. However, for Lab 8, the data found in the files will be in a different order than in Lab 7. The data will be grouped such that a struct data type can be used to read and write to the binary file. Background Preparation: Review file I/O for ascii and binary formats and command line arguments, and make sure that your Lab 7 programs work correctly. Specifications: Your programs will use the following structure to hold the data that is read and to be written:
typedef struct _FileData { int a; double b; char dataStr[50]; } FileData;
Both programs will obtain the filenames to be read and written from command line parameters:
bash$ AsciiToBinary ascii_in binary_out bash$ BinaryToAscii binary_in ascii_out
The data format in the ASCII format files (both reading and writing) will be one data item per line:
47 34.278 This is a line of text
Sample ASCII and binary format files are provided. There will be a set of three lines for each FileData structure's data. There will be no blank lines between each set of three lines. There is no limit to the number of three line sets a file may contain. You can assume that there will be no data in the file that is not grouped as a set, and each text string will be 50 characters or less (including the NULL terminator). Note that although there will always be an integer and a floating point value, it is possible that the data string will be empty (i.e. a blank line). Important: Make sure there is no blank line at the end of the ASCII file. The size of each record for the binary file will be the same as the size of the FileData structure. The specific method that you use to read and write the data is up to you. You may wish to read all the data from the input file before writing to the output file, or you may wish to write each record as it is read. Be sure to close both files (input and output) before exiting the program. Testing: Besides testing your code with your usual methods, you should also test your programs by reading an ASCII file, converting it to binary, then reading the converted binary file and converting it back to ASCII. The new ASCII file should match exactly with the original ASCII file.
Where you can download files:
ascii_file_2.txt
https://www.dropbox.com/s/oa7hqm6cg63afiq/ascii_file_2.txt?dl=0
binary_file(2).bin
https://www.dropbox.com/s/rs0oh51gyeqcz6f/binary_file%282%29.bin?dl=0
Please answer this question as fast as you can
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
