SlideShare a Scribd company logo
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,"%st%st%dt%0.2f ",data[n].firstname,data[n].lastname,data[n].id,tgpa);
n++;
}
// print the data
for(i=0;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;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;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
Solution
Steps to Compile using gcc compiler on linux platform:
#1. gcc main.c binarytotext.c texttobinary.c [this will make a.out executable]
#2. ./a.out [we can run a.out in this way]
Note: Calling sequence of binaryToText_main() and textToBinary_main() depends on your
functionality.
----------------------
File#1 [main.c]
----------------------
#include "header.h"
int main()
{
binaryToText_main();
textToBinary_main();
return 0;
}
--------------------------------
File#2 [texttobinary.c]
--------------------------------
#include "header.h"
int textToBinary_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);
}
---------------------------------
File#3 [binarytotext.c]
---------------------------------
#include "header.h"
//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);
// returns the index of student having longest name
int binaryToText_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,"%st%st%dt%0.2f ",data[n].firstname,data[n].lastname,data[n].id,tgpa);
n++;
}
// print the data
for(i=0;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;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;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
#include
#include
struct student
{
char firstname[255],lastname[255];
unsigned int id;
float gpa;
};
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);

More Related Content

Similar to Here is my code. There are Two C Programs which need to follow the a.pdf

httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docx
adampcarr67227
 
Write a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfWrite a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdf
jillisacebi75827
 
C programming session 08
C programming session 08C programming session 08
C programming session 08Dushmanta Nath
 
IN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfIN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdf
aratextails30
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
radhushri
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)mrecedu
 
Pl python python w postgre-sql
Pl python   python w postgre-sqlPl python   python w postgre-sql
Pl python python w postgre-sql
Piotr Pałkiewicz
 
Data structures
Data structuresData structures
Data structures
gayatrigayu1
 
Perl 1997 Perl As A System Glue
Perl 1997 Perl As A System GluePerl 1997 Perl As A System Glue
Perl 1997 Perl As A System Glue
Patrick Benson
 
WK-12-13-file f classs 12 computer science from kv.
WK-12-13-file f classs 12 computer science from kv.WK-12-13-file f classs 12 computer science from kv.
WK-12-13-file f classs 12 computer science from kv.
niwashannamalai0715
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ewout2
 
Python 3000
Python 3000Python 3000
Python 3000
Alexandro Colorado
 
Sp ch05
Sp ch05Sp ch05
General Functions
General FunctionsGeneral Functions
General Functions
BabuDevanandam
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
ChereCheek752
 
C Language Unit-5
C Language Unit-5C Language Unit-5
C Language Unit-5
kasaragadda srinivasrao
 

Similar to Here is my code. There are Two C Programs which need to follow the a.pdf (20)

httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docx
 
Write a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfWrite a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdf
 
Unit5 C
Unit5 C Unit5 C
Unit5 C
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
 
IN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfIN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdf
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
file handling final3333.pptx
file handling final3333.pptxfile handling final3333.pptx
file handling final3333.pptx
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)
 
Pl python python w postgre-sql
Pl python   python w postgre-sqlPl python   python w postgre-sql
Pl python python w postgre-sql
 
Data structures
Data structuresData structures
Data structures
 
08 -functions
08  -functions08  -functions
08 -functions
 
7512635.ppt
7512635.ppt7512635.ppt
7512635.ppt
 
Perl 1997 Perl As A System Glue
Perl 1997 Perl As A System GluePerl 1997 Perl As A System Glue
Perl 1997 Perl As A System Glue
 
WK-12-13-file f classs 12 computer science from kv.
WK-12-13-file f classs 12 computer science from kv.WK-12-13-file f classs 12 computer science from kv.
WK-12-13-file f classs 12 computer science from kv.
 
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaaShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
ShellAdvanced aaäaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Python 3000
Python 3000Python 3000
Python 3000
 
Sp ch05
Sp ch05Sp ch05
Sp ch05
 
General Functions
General FunctionsGeneral Functions
General Functions
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
 
C Language Unit-5
C Language Unit-5C Language Unit-5
C Language Unit-5
 

More from fcaindore

You are the CIO of a medium size company tasked with modernizing the.pdf
You are the CIO of a medium size company tasked with modernizing the.pdfYou are the CIO of a medium size company tasked with modernizing the.pdf
You are the CIO of a medium size company tasked with modernizing the.pdf
fcaindore
 
Why are some goods only provided by the government Why are .pdf
Why are some goods only provided by the government Why are .pdfWhy are some goods only provided by the government Why are .pdf
Why are some goods only provided by the government Why are .pdf
fcaindore
 
When a supervisor comes to the HR manager to evaluate disciplinary a.pdf
When a supervisor comes to the HR manager to evaluate disciplinary a.pdfWhen a supervisor comes to the HR manager to evaluate disciplinary a.pdf
When a supervisor comes to the HR manager to evaluate disciplinary a.pdf
fcaindore
 
What is the role of an ethical leader in corporate cultures a. A le.pdf
What is the role of an ethical leader in corporate cultures a. A le.pdfWhat is the role of an ethical leader in corporate cultures a. A le.pdf
What is the role of an ethical leader in corporate cultures a. A le.pdf
fcaindore
 
What is the main purpose of a project management planSolution.pdf
What is the main purpose of a project management planSolution.pdfWhat is the main purpose of a project management planSolution.pdf
What is the main purpose of a project management planSolution.pdf
fcaindore
 
What is the difference between a balanace sheet and a net income she.pdf
What is the difference between a balanace sheet and a net income she.pdfWhat is the difference between a balanace sheet and a net income she.pdf
What is the difference between a balanace sheet and a net income she.pdf
fcaindore
 
What is involved in personalization and codification of tacit to exp.pdf
What is involved in personalization and codification of tacit to exp.pdfWhat is involved in personalization and codification of tacit to exp.pdf
What is involved in personalization and codification of tacit to exp.pdf
fcaindore
 
What dimensions of quality were highlighted in the Delta Airlines ba.pdf
What dimensions of quality were highlighted in the Delta Airlines ba.pdfWhat dimensions of quality were highlighted in the Delta Airlines ba.pdf
What dimensions of quality were highlighted in the Delta Airlines ba.pdf
fcaindore
 
What are the similarities and differences between the ETC of Photosy.pdf
What are the similarities and differences between the ETC of Photosy.pdfWhat are the similarities and differences between the ETC of Photosy.pdf
What are the similarities and differences between the ETC of Photosy.pdf
fcaindore
 
What are non-tax costs of tax planningSolutionFollowings are .pdf
What are non-tax costs of tax planningSolutionFollowings are .pdfWhat are non-tax costs of tax planningSolutionFollowings are .pdf
What are non-tax costs of tax planningSolutionFollowings are .pdf
fcaindore
 
There is a host of sociological and cultural research that paints a r.pdf
There is a host of sociological and cultural research that paints a r.pdfThere is a host of sociological and cultural research that paints a r.pdf
There is a host of sociological and cultural research that paints a r.pdf
fcaindore
 
True or False With argument passage by reference, the address of the.pdf
True or False With argument passage by reference, the address of the.pdfTrue or False With argument passage by reference, the address of the.pdf
True or False With argument passage by reference, the address of the.pdf
fcaindore
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
fcaindore
 
SOme of functions of the eukaryotic orgenelles are performed in bact.pdf
SOme of functions of the eukaryotic orgenelles are performed in bact.pdfSOme of functions of the eukaryotic orgenelles are performed in bact.pdf
SOme of functions of the eukaryotic orgenelles are performed in bact.pdf
fcaindore
 
please explain the global entreprenurship revolution for a flatter w.pdf
please explain the global entreprenurship revolution for a flatter w.pdfplease explain the global entreprenurship revolution for a flatter w.pdf
please explain the global entreprenurship revolution for a flatter w.pdf
fcaindore
 
ourse O D. growth rate of currency in circulation-growth rate of the .pdf
ourse O D. growth rate of currency in circulation-growth rate of the .pdfourse O D. growth rate of currency in circulation-growth rate of the .pdf
ourse O D. growth rate of currency in circulation-growth rate of the .pdf
fcaindore
 
Modify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdfModify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdf
fcaindore
 
Many hospitals have systems in place and are now or will in the futu.pdf
Many hospitals have systems in place and are now or will in the futu.pdfMany hospitals have systems in place and are now or will in the futu.pdf
Many hospitals have systems in place and are now or will in the futu.pdf
fcaindore
 
List the S + D and the organism that causes a vesicle, Gumma, purule.pdf
List the S + D and the organism that causes a vesicle, Gumma, purule.pdfList the S + D and the organism that causes a vesicle, Gumma, purule.pdf
List the S + D and the organism that causes a vesicle, Gumma, purule.pdf
fcaindore
 
Let k be the number of ON-state devices in a group of n devices on a .pdf
Let k be the number of ON-state devices in a group of n devices on a .pdfLet k be the number of ON-state devices in a group of n devices on a .pdf
Let k be the number of ON-state devices in a group of n devices on a .pdf
fcaindore
 

More from fcaindore (20)

You are the CIO of a medium size company tasked with modernizing the.pdf
You are the CIO of a medium size company tasked with modernizing the.pdfYou are the CIO of a medium size company tasked with modernizing the.pdf
You are the CIO of a medium size company tasked with modernizing the.pdf
 
Why are some goods only provided by the government Why are .pdf
Why are some goods only provided by the government Why are .pdfWhy are some goods only provided by the government Why are .pdf
Why are some goods only provided by the government Why are .pdf
 
When a supervisor comes to the HR manager to evaluate disciplinary a.pdf
When a supervisor comes to the HR manager to evaluate disciplinary a.pdfWhen a supervisor comes to the HR manager to evaluate disciplinary a.pdf
When a supervisor comes to the HR manager to evaluate disciplinary a.pdf
 
What is the role of an ethical leader in corporate cultures a. A le.pdf
What is the role of an ethical leader in corporate cultures a. A le.pdfWhat is the role of an ethical leader in corporate cultures a. A le.pdf
What is the role of an ethical leader in corporate cultures a. A le.pdf
 
What is the main purpose of a project management planSolution.pdf
What is the main purpose of a project management planSolution.pdfWhat is the main purpose of a project management planSolution.pdf
What is the main purpose of a project management planSolution.pdf
 
What is the difference between a balanace sheet and a net income she.pdf
What is the difference between a balanace sheet and a net income she.pdfWhat is the difference between a balanace sheet and a net income she.pdf
What is the difference between a balanace sheet and a net income she.pdf
 
What is involved in personalization and codification of tacit to exp.pdf
What is involved in personalization and codification of tacit to exp.pdfWhat is involved in personalization and codification of tacit to exp.pdf
What is involved in personalization and codification of tacit to exp.pdf
 
What dimensions of quality were highlighted in the Delta Airlines ba.pdf
What dimensions of quality were highlighted in the Delta Airlines ba.pdfWhat dimensions of quality were highlighted in the Delta Airlines ba.pdf
What dimensions of quality were highlighted in the Delta Airlines ba.pdf
 
What are the similarities and differences between the ETC of Photosy.pdf
What are the similarities and differences between the ETC of Photosy.pdfWhat are the similarities and differences between the ETC of Photosy.pdf
What are the similarities and differences between the ETC of Photosy.pdf
 
What are non-tax costs of tax planningSolutionFollowings are .pdf
What are non-tax costs of tax planningSolutionFollowings are .pdfWhat are non-tax costs of tax planningSolutionFollowings are .pdf
What are non-tax costs of tax planningSolutionFollowings are .pdf
 
There is a host of sociological and cultural research that paints a r.pdf
There is a host of sociological and cultural research that paints a r.pdfThere is a host of sociological and cultural research that paints a r.pdf
There is a host of sociological and cultural research that paints a r.pdf
 
True or False With argument passage by reference, the address of the.pdf
True or False With argument passage by reference, the address of the.pdfTrue or False With argument passage by reference, the address of the.pdf
True or False With argument passage by reference, the address of the.pdf
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
 
SOme of functions of the eukaryotic orgenelles are performed in bact.pdf
SOme of functions of the eukaryotic orgenelles are performed in bact.pdfSOme of functions of the eukaryotic orgenelles are performed in bact.pdf
SOme of functions of the eukaryotic orgenelles are performed in bact.pdf
 
please explain the global entreprenurship revolution for a flatter w.pdf
please explain the global entreprenurship revolution for a flatter w.pdfplease explain the global entreprenurship revolution for a flatter w.pdf
please explain the global entreprenurship revolution for a flatter w.pdf
 
ourse O D. growth rate of currency in circulation-growth rate of the .pdf
ourse O D. growth rate of currency in circulation-growth rate of the .pdfourse O D. growth rate of currency in circulation-growth rate of the .pdf
ourse O D. growth rate of currency in circulation-growth rate of the .pdf
 
Modify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdfModify the project so tat records are inserted into the random acess.pdf
Modify the project so tat records are inserted into the random acess.pdf
 
Many hospitals have systems in place and are now or will in the futu.pdf
Many hospitals have systems in place and are now or will in the futu.pdfMany hospitals have systems in place and are now or will in the futu.pdf
Many hospitals have systems in place and are now or will in the futu.pdf
 
List the S + D and the organism that causes a vesicle, Gumma, purule.pdf
List the S + D and the organism that causes a vesicle, Gumma, purule.pdfList the S + D and the organism that causes a vesicle, Gumma, purule.pdf
List the S + D and the organism that causes a vesicle, Gumma, purule.pdf
 
Let k be the number of ON-state devices in a group of n devices on a .pdf
Let k be the number of ON-state devices in a group of n devices on a .pdfLet k be the number of ON-state devices in a group of n devices on a .pdf
Let k be the number of ON-state devices in a group of n devices on a .pdf
 

Recently uploaded

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

Here is my code. There are Two C Programs which need to follow the a.pdf

  • 1. 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];
  • 2. 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;
  • 3. fprintf(fout,"%st%st%dt%0.2f ",data[n].firstname,data[n].lastname,data[n].id,tgpa); n++; } // print the data for(i=0;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;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;imax) { max=data[i].id; index=i; }
  • 4. } 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 Solution Steps to Compile using gcc compiler on linux platform: #1. gcc main.c binarytotext.c texttobinary.c [this will make a.out executable] #2. ./a.out [we can run a.out in this way] Note: Calling sequence of binaryToText_main() and textToBinary_main() depends on your functionality. ---------------------- File#1 [main.c] ---------------------- #include "header.h" int main() { binaryToText_main(); textToBinary_main(); return 0; } -------------------------------- File#2 [texttobinary.c] -------------------------------- #include "header.h" int textToBinary_main() { FILE *fpIn, *fpOut; fpIn = fopen("TextToBinaryInput.txt", "r"); fpOut = fopen("TextToBinaryOutput.txt", "wb");
  • 5. 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); } --------------------------------- File#3 [binarytotext.c] --------------------------------- #include "header.h" //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); // returns the index of student having longest name int binaryToText_main() { struct student data[20]; // array of student
  • 6. 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,"%st%st%dt%0.2f ",data[n].firstname,data[n].lastname,data[n].id,tgpa); n++; } // print the data for(i=0;imaxlen) { maxlen=strlen(data[i].firstname)+strlen(data[i].firstname); index=i; } } return index; } // returns the index of student having shortest name
  • 7. int shortestName(struct student data[],int n) { int i,minlen,index=0; minlen=strlen(data[0].firstname)+strlen(data[0].lastname); 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;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 #include #include
  • 8. struct student { char firstname[255],lastname[255]; unsigned int id; float gpa; }; 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);