Here is the code I have for Part 1 include include int main

Here is the code I have for Part 1:

#include <stdio.h>
#include <string.h>
int main()
{
FILE *fpIn, *fpOut;
fpIn = fopen(\"TextToBinaryInput.txt\", \"r\");
fpOut = fopen(\"TextToBinaryOutput.txt\", \"wb\");
char firstName[255], lastName[255];
unsigned int id;
float gpa;
unsigned char firstLength, lastLength;
while(!feof(fpIn))
{
fscanf(fpIn, \"%s%s%u%f\", firstName, lastName, &id, &gpa);
//printf(\"%s %s %u %f\ \", firstName, lastName, id, gpa);
firstLength = strlen(firstName);
lastLength = strlen(lastName);
fwrite(&firstLength, 1, 1, fpOut);
fwrite(firstName, 1, firstLength, fpOut);
fwrite(&lastLength, 1, 1, fpOut);
fwrite(lastName, 1, lastLength, fpOut);
fwrite(&id, 4, 1, fpOut);
fwrite(&gpa, 4, 1, fpOut);
}
fclose(fpIn);
fclose(fpOut);
}

Need help with part 2 of the assignment from converting a binary text file back to text.

The executable version of your program must be named converter. (Your makefile should ensure this. Your program will be executed using a Unix command line of form converter fag infile outfile or converter -s infile Description of the first form: In the first form of the Unix command line, the parameters infile and outfile represent the names of the input and output files respectively. The parameter fiag may be either -t or -b. When the fag parameter is -t, the input file is a text file and the output file must be the binary file containing the representation for each line as described above. Similarly, when the flag parameter is -b, the input file is a binary file containing the representations of the lines of a text file, and the output file must be the corresponding text file Description of the second form In the second form of the Unix command, the command line parameter in e represents the name of the binary input file (which was created previously from a text file Note that the only flag that is permitted in this form is -s. Here, your program must process the input (binary) file and produce the following information to st dout. In this case, your progra should not produce an output file (a) The full name of the student with the greatest combined name length (i.e. the student for which El E 2 is that of each other student (b) The full name of the student with the least combined name length e. the student for which l1 E 2 is S that of each other student (c) The value of the highest id number (d) The value of the lowest id number (e) The value of the highest GPA (g) The value of the lowest GPA You may assume the following. (There is no need to test for these conditions in your program (1) Each text file will have at least one line (2) Each string in a text file will have at least 1 and at most 255 characters. Further, the string won\'t contain white space characters

Solution

#include <stdio.h>
#include <string.h>
int main()
{
FILE *fpIn, *fpOut;
fpIn = fopen(\"TextToBinaryInput.txt\", \"r\");
fpOut = fopen(\"TextToBinaryOutput.txt\", \"wb\");
char firstName[255], lastName[255];
unsigned int id;
float gpa;
unsigned char firstLength, lastLength;
while(!feof(fpIn))
{
fscanf(fpIn, \"%s%s%u%f\", firstName, lastName, &id, &gpa);
//printf(\"%s %s %u %f\ \", firstName, lastName, id, gpa);
firstLength = strlen(firstName);
lastLength = strlen(lastName);
fwrite(&firstLength, 1, 1, fpOut);
fwrite(firstName, 1, firstLength, fpOut);
fwrite(&lastLength, 1, 1, fpOut);
fwrite(lastName, 1, lastLength, fpOut);
fwrite(&id, 4, 1, fpOut);
fwrite(&gpa, 4, 1, fpOut);
}
fclose(fpIn);
fclose(fpOut);
}

Here is the code I have for Part 1: #include <stdio.h> #include <string.h> int main() { FILE *fpIn, *fpOut; fpIn = fopen(\
Here is the code I have for Part 1: #include <stdio.h> #include <string.h> int main() { FILE *fpIn, *fpOut; fpIn = fopen(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site