Question
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:
Here is my code. There are Two C Programs which need to follow the above format
TexttoBinary.C
#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 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;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;i // 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;i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started