SlideShare a Scribd company logo
1 of 8
Download to read offline
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.docxadampcarr67227
 
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.pdfjillisacebi75827
 
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.pdfaratextails30
 
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.pptxradhushri
 
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-sqlPiotr Pałkiewicz
 
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 GluePatrick 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äaaaaaaaaaaaaaaaaaaaaaaaaaaaewout2
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bChereCheek752
 

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.pdffcaindore
 
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 .pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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 .pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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 .pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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.pdffcaindore
 
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 .pdffcaindore
 

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

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 

Recently uploaded (20)

INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 

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