Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need Some help with C programming: Ive got the code I just need it to follow the given structure: Here is my code. There are

Need Some help with C programming: Ive got the code I just need it to follow the given structure:image text in transcribed

Here is my code. There are Two C Programs which need to follow the above format

TexttoBinary.C

#include #include

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);

}

BinarytoText.C

#include #include #include //stdtent data type to store info struct student { char firstname[255],lastname[255]; unsigned int id; float gpa; }; //function prototypes int longestName(struct student data[],int n); int shortestName(struct student data[],int n); int highestId(struct student data[],int n); int lowestId(struct student data[],int n); int highestGPA(struct student data[],int n); int lowestGPA(struct student data[],int n); //////////////////// int main() { struct student data[20]; // array of student int n,i; float tgpa; FILE *fp,*fout; int longestname,shortestname; int highestid,lowestid; int highestgpa,lowestgpa; fp=fopen("bina.dat","rb"); // open the binary file if(fp==NULL) { printf("Unable to open file"); exit(0); } fout=fopen("tex.txt","w"); //open the text file n=0; //scan the binary file continiously and store the data in text file as well as in array of student structure while(fscanf(fp,"%s%s%d%f",data[n].firstname,data[n].lastname,&data[n].id,&tgpa)!=EOF) { data[n].gpa=tgpa; fprintf(fout,"%s\t%s\t%d\t%0.2f ",data[n].firstname,data[n].lastname,data[n].id,tgpa); n++; } // print the data for(i=0;i

return 0; } // returns the index of student having longest name int longestName(struct student data[],int n) { int i,maxlen,index=0; maxlen=strlen(data[0].firstname)+strlen(data[0].lastname); for(i=1;imaxlen) { maxlen=strlen(data[i].firstname)+strlen(data[i].firstname); index=i; } } return index; } // returns the index of student having shortest name int shortestName(struct student data[],int n) { int i,minlen,index=0; minlen=strlen(data[0].firstname)+strlen(data[0].lastname); for(i=1;i

// returns the index of student having highest gpa int highestGPA(struct student data[],int n) { int i,max,index=0; max=data[0].gpa; for(i=1;imax) { max=data[i].gpa; index=i; } } return index; }<>

// returns the index of student having lowest id int lowestId(struct student data[],int n) { int i,min,index=0; min=data[0].id; for(i=1;i

// returns the index of student having highest id int highestId(struct student data[],int n) { int i,max,index=0; max=data[0].id; for(i=1;imax) { max=data[i].id; index=i; } } return index; } // returns the index of student having lowest gpa int lowestGPA(struct student data[],int n) { int i,min,index=0; min=data[0].gpa; for(i=1;i Structural requirement: Your program must must contain at least the following files: A C source file containing only the main function A C source file containing only the function to convert a text file into a binary file A C source file containing only the function to convert a binary file into a text file A header file containing function prototypes for the conversion functions<><>

<>

<><>

<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Question What happens to my plan if I die?

Answered: 1 week ago

Question

What are the main differences between rigid and flexible pavements?

Answered: 1 week ago

Question

What is the purpose of a retaining wall, and how is it designed?

Answered: 1 week ago

Question

How do you determine the load-bearing capacity of a soil?

Answered: 1 week ago

Question

what is Edward Lemieux effect / Anomeric effect ?

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago