SlideShare a Scribd company logo
1 of 5
Download to read offline
C programming.
For this code I only need to add a function so that the array of pointers is sorted by the age of the
individual entered.
it must be a function and called in main . That is the only thing needed.
#define _CRT_SECURE_NO_WARNINGS
#include
#include
#define PAUSE system("pause")
typedef struct {
int age;
int weight;
int height;
} STATS;
STATS *makeArrayOfPointers(int );
void loadArray(STATS **array, int *c);
void displayArray(STATS **array, int c);
void saveArray(STATS **array, int count, int size);
STATS **reloadArray(char *, int *count, int *size);
main() {
STATS** array = 0;
int count = 0;
int size = 500;
char reloaded = 'N';
array = reloadArray(&reloaded, &count, &size);
if(reloaded == 'N')
array = makeArrayOfPointers(size);
PAUSE;
loadArray(array, &count);
printf("** unSorted Array ** ");
displayArray(array, count);
//sortArray(array, count)
printf("** Sorted by Age ** ");
displayArray(array, count);
saveArray(array, count, size);
PAUSE;
} // end of main
void displayArray(STATS **array, int c) {
int i;
for (i = 0; i < c; i++) {
printf("Record[%i] Age is %i.t Weight is %i.t Height is %i. ", i, array[i]->age, array[i]-
>weight, array[i]->height);
}
PAUSE;
} // end displayArray
void loadArray(STATS **array, int *c) {
int value;
int counter = *c;
for (*c; *c < (counter + 4); *c = *c + 1) {
printf("  Information for person: %i  ", (*c) + 1);
array[*c] = calloc(1, sizeof(STATS));
printf("Enter age: ");
scanf("%i", &value);
array[*c]->age = value;
printf("Enter weight: ");
scanf("%i", &value);
array[*c]->weight = value;
printf("Enter height: ");
scanf("%i", &value);
array[*c]->height = value;
} // end for
} // end loadArray
STATS *makeArrayOfPointers(int size) {
STATS *result;
result = malloc(sizeof(STATS*) * size);
return result;
} // end makeArrayOfPointers
void saveArray(STATS **array, int count, int size) {
FILE *ptr;
int i;
ptr = fopen("c:myBinFile.bin", "wb");
if (ptr == NULL) {
printf("Could not open the file ");
PAUSE;
exit(-1);
}
// SAVE THE SIZE OF THE ARRAY
fwrite(&size, sizeof(int), 1, ptr);
// SAVE THE EFFECTIVE SIZE or COUNT
fwrite(&count, sizeof(int), 1, ptr);
// SAVE EACH NODE/ELEMENT in the ARRAY
for (i = 0; i < count; i++) {
fwrite(array[i], sizeof(STATS), 1, ptr);
} // end for
fclose(ptr);
}// end saveArray
STATS **reloadArray(char *result, int *count, int *size) {
STATS **temp = 0;
FILE *ptr;
int i;
*result = 'Y';
ptr = fopen("c:myBinFile.bin", "rb");
if (ptr == NULL) {
printf("Could not open the file ");
PAUSE;
*result = 'N';
}
else {
// Reload the size of the array
fread(size, sizeof(int), 1, ptr);
// Create the Array of Pointers
temp = makeArrayOfPointers(*size);
// Reload the count or effective size variable
fread(count, sizeof(int), 1, ptr);
// Reload the nodes or elements of the array
for (i = 0; i < *count; i++) {
temp[i] = calloc(1, sizeof(STATS));
fread(temp[i], sizeof(STATS), 1, ptr);
}
} // end else
fclose(ptr);
return temp;
}// end reloadArray
Solution
//Declare function prototype above main function
void sortArray(STATS **array, int count);
//call sortArray function in main fuction
sortArray(array, count);
//Write the function defination as fallows
/*I have used Bubble sort technique to sort the array. The following code will sort the array in
ascending order of age. In Bubble sort it checks the cosecutive elements of array and swaps the
elements if first element is greater than second element. Keep checking elements till end so that
the greatest element will move to last position of array. */
void sortArray(STATS **array, int count)
{
STATS **temp;
int i,j;
//No. of Iterations required
for(i=0;iage > array[j+1]->age)
{
//swapping of array elements
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}//end of if
}//end of j loop
}//end of i loop
}//end of fuction

More Related Content

Similar to C programming.   For this code I only need to add a function so th.pdf

I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfezzi552
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of cTushar B Kute
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with PythonHan Lee
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdfherminaherman
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdffsenterprises
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and GoEleanor McHugh
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Saket Pathak
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxcgraciela1
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfarri2009av
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questionsSrikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3Srikanth
 
In c code, fill in the blank#include time.h#include std.pdf
In c code, fill in the blank#include time.h#include std.pdfIn c code, fill in the blank#include time.h#include std.pdf
In c code, fill in the blank#include time.h#include std.pdfmanojmozy
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTsKevlin Henney
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdffashiongallery1
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdfanandatalapatra
 
#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docxgertrudebellgrove
 

Similar to C programming.   For this code I only need to add a function so th.pdf (20)

I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
Getting the following errorsError 1 error C2436 {ctor}  mem.pdfGetting the following errorsError 1 error C2436 {ctor}  mem.pdf
Getting the following errorsError 1 error C2436 {ctor} mem.pdf
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
 
Implementing Software Machines in C and Go
Implementing Software Machines in C and GoImplementing Software Machines in C and Go
Implementing Software Machines in C and Go
 
week-16x
week-16xweek-16x
week-16x
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
In c code, fill in the blank#include time.h#include std.pdf
In c code, fill in the blank#include time.h#include std.pdfIn c code, fill in the blank#include time.h#include std.pdf
In c code, fill in the blank#include time.h#include std.pdf
 
C
CC
C
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdfUsing standard libraries like stdio and sdtlib.h and using stats.h a.pdf
Using standard libraries like stdio and sdtlib.h and using stats.h a.pdf
 
c programming
c programmingc programming
c programming
 
#include iostream #include cstring #include vector #i.pdf
 #include iostream #include cstring #include vector #i.pdf #include iostream #include cstring #include vector #i.pdf
#include iostream #include cstring #include vector #i.pdf
 
#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx
 

More from badshetoms

Determining Cash Payments to StockholdersThe board of directors de.pdf
Determining Cash Payments to StockholdersThe board of directors de.pdfDetermining Cash Payments to StockholdersThe board of directors de.pdf
Determining Cash Payments to StockholdersThe board of directors de.pdfbadshetoms
 
Assume that Stanford CPAs encountered the following issues during va.pdf
Assume that Stanford CPAs encountered the following issues during va.pdfAssume that Stanford CPAs encountered the following issues during va.pdf
Assume that Stanford CPAs encountered the following issues during va.pdfbadshetoms
 
Because his last undergrad research assistant died on the job, Profes.pdf
Because his last undergrad research assistant died on the job, Profes.pdfBecause his last undergrad research assistant died on the job, Profes.pdf
Because his last undergrad research assistant died on the job, Profes.pdfbadshetoms
 
When a coalition of credit card companies form an interest group cal.pdf
When a coalition of credit card companies form an interest group cal.pdfWhen a coalition of credit card companies form an interest group cal.pdf
When a coalition of credit card companies form an interest group cal.pdfbadshetoms
 
What is the relationship between government and economicsWh.pdf
What is the relationship between government and economicsWh.pdfWhat is the relationship between government and economicsWh.pdf
What is the relationship between government and economicsWh.pdfbadshetoms
 
Which method, streak or pour plate is easier for obtaining cultur.pdf
Which method, streak or pour plate is easier for obtaining cultur.pdfWhich method, streak or pour plate is easier for obtaining cultur.pdf
Which method, streak or pour plate is easier for obtaining cultur.pdfbadshetoms
 
Write an algorithm in pseudocode called copy Stack that copies the co.pdf
Write an algorithm in pseudocode called copy Stack that copies the co.pdfWrite an algorithm in pseudocode called copy Stack that copies the co.pdf
Write an algorithm in pseudocode called copy Stack that copies the co.pdfbadshetoms
 
Use properties of logarithms to condense 4 ln x-6 ln y. Write the .pdf
Use properties of logarithms to condense 4 ln x-6 ln y. Write the .pdfUse properties of logarithms to condense 4 ln x-6 ln y. Write the .pdf
Use properties of logarithms to condense 4 ln x-6 ln y. Write the .pdfbadshetoms
 
What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdf
What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdfWhat is the Insertion Sort MIPS Assembly codeSolution.globl m.pdf
What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdfbadshetoms
 
9. How much would it cost to construct a building today that cost $12.pdf
9. How much would it cost to construct a building today that cost $12.pdf9. How much would it cost to construct a building today that cost $12.pdf
9. How much would it cost to construct a building today that cost $12.pdfbadshetoms
 
True or false 20. A manufacturer has a duty to warn about risks that.pdf
True or false 20. A manufacturer has a duty to warn about risks that.pdfTrue or false 20. A manufacturer has a duty to warn about risks that.pdf
True or false 20. A manufacturer has a duty to warn about risks that.pdfbadshetoms
 
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdf
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdfto a 1911 in an effort to reduce violence against Suffragettes of NAW.pdf
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdfbadshetoms
 
There are many cases of human disease where an enzyme activity is lac.pdf
There are many cases of human disease where an enzyme activity is lac.pdfThere are many cases of human disease where an enzyme activity is lac.pdf
There are many cases of human disease where an enzyme activity is lac.pdfbadshetoms
 
The United states has utilize multiple forms of liberalism through o.pdf
The United states has utilize multiple forms of liberalism through o.pdfThe United states has utilize multiple forms of liberalism through o.pdf
The United states has utilize multiple forms of liberalism through o.pdfbadshetoms
 
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdf
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdfCalculator 26 ng Learning pose that the Fed engages in expansionary.pdf
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdfbadshetoms
 
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdf
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdfSilver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdf
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdfbadshetoms
 
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdf
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdfProblem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdf
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdfbadshetoms
 
Privacy and Security What types of health care data are protected u.pdf
Privacy and Security What types of health care data are protected u.pdfPrivacy and Security What types of health care data are protected u.pdf
Privacy and Security What types of health care data are protected u.pdfbadshetoms
 
1. Project risk is normally highest during the project Executing Pro.pdf
1. Project risk is normally highest during the project Executing Pro.pdf1. Project risk is normally highest during the project Executing Pro.pdf
1. Project risk is normally highest during the project Executing Pro.pdfbadshetoms
 
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdfPLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdfbadshetoms
 

More from badshetoms (20)

Determining Cash Payments to StockholdersThe board of directors de.pdf
Determining Cash Payments to StockholdersThe board of directors de.pdfDetermining Cash Payments to StockholdersThe board of directors de.pdf
Determining Cash Payments to StockholdersThe board of directors de.pdf
 
Assume that Stanford CPAs encountered the following issues during va.pdf
Assume that Stanford CPAs encountered the following issues during va.pdfAssume that Stanford CPAs encountered the following issues during va.pdf
Assume that Stanford CPAs encountered the following issues during va.pdf
 
Because his last undergrad research assistant died on the job, Profes.pdf
Because his last undergrad research assistant died on the job, Profes.pdfBecause his last undergrad research assistant died on the job, Profes.pdf
Because his last undergrad research assistant died on the job, Profes.pdf
 
When a coalition of credit card companies form an interest group cal.pdf
When a coalition of credit card companies form an interest group cal.pdfWhen a coalition of credit card companies form an interest group cal.pdf
When a coalition of credit card companies form an interest group cal.pdf
 
What is the relationship between government and economicsWh.pdf
What is the relationship between government and economicsWh.pdfWhat is the relationship between government and economicsWh.pdf
What is the relationship between government and economicsWh.pdf
 
Which method, streak or pour plate is easier for obtaining cultur.pdf
Which method, streak or pour plate is easier for obtaining cultur.pdfWhich method, streak or pour plate is easier for obtaining cultur.pdf
Which method, streak or pour plate is easier for obtaining cultur.pdf
 
Write an algorithm in pseudocode called copy Stack that copies the co.pdf
Write an algorithm in pseudocode called copy Stack that copies the co.pdfWrite an algorithm in pseudocode called copy Stack that copies the co.pdf
Write an algorithm in pseudocode called copy Stack that copies the co.pdf
 
Use properties of logarithms to condense 4 ln x-6 ln y. Write the .pdf
Use properties of logarithms to condense 4 ln x-6 ln y. Write the .pdfUse properties of logarithms to condense 4 ln x-6 ln y. Write the .pdf
Use properties of logarithms to condense 4 ln x-6 ln y. Write the .pdf
 
What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdf
What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdfWhat is the Insertion Sort MIPS Assembly codeSolution.globl m.pdf
What is the Insertion Sort MIPS Assembly codeSolution.globl m.pdf
 
9. How much would it cost to construct a building today that cost $12.pdf
9. How much would it cost to construct a building today that cost $12.pdf9. How much would it cost to construct a building today that cost $12.pdf
9. How much would it cost to construct a building today that cost $12.pdf
 
True or false 20. A manufacturer has a duty to warn about risks that.pdf
True or false 20. A manufacturer has a duty to warn about risks that.pdfTrue or false 20. A manufacturer has a duty to warn about risks that.pdf
True or false 20. A manufacturer has a duty to warn about risks that.pdf
 
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdf
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdfto a 1911 in an effort to reduce violence against Suffragettes of NAW.pdf
to a 1911 in an effort to reduce violence against Suffragettes of NAW.pdf
 
There are many cases of human disease where an enzyme activity is lac.pdf
There are many cases of human disease where an enzyme activity is lac.pdfThere are many cases of human disease where an enzyme activity is lac.pdf
There are many cases of human disease where an enzyme activity is lac.pdf
 
The United states has utilize multiple forms of liberalism through o.pdf
The United states has utilize multiple forms of liberalism through o.pdfThe United states has utilize multiple forms of liberalism through o.pdf
The United states has utilize multiple forms of liberalism through o.pdf
 
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdf
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdfCalculator 26 ng Learning pose that the Fed engages in expansionary.pdf
Calculator 26 ng Learning pose that the Fed engages in expansionary.pdf
 
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdf
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdfSilver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdf
Silver chromate is sparingly soluble in aqueous solutions. The Ksp o.pdf
 
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdf
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdfProblem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdf
Problem 21.12 Histone genes are unusual among eukaryotic genes becaus.pdf
 
Privacy and Security What types of health care data are protected u.pdf
Privacy and Security What types of health care data are protected u.pdfPrivacy and Security What types of health care data are protected u.pdf
Privacy and Security What types of health care data are protected u.pdf
 
1. Project risk is normally highest during the project Executing Pro.pdf
1. Project risk is normally highest during the project Executing Pro.pdf1. Project risk is normally highest during the project Executing Pro.pdf
1. Project risk is normally highest during the project Executing Pro.pdf
 
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdfPLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
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
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
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
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Recently uploaded (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
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
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.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
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

C programming.   For this code I only need to add a function so th.pdf

  • 1. C programming. For this code I only need to add a function so that the array of pointers is sorted by the age of the individual entered. it must be a function and called in main . That is the only thing needed. #define _CRT_SECURE_NO_WARNINGS #include #include #define PAUSE system("pause") typedef struct { int age; int weight; int height; } STATS; STATS *makeArrayOfPointers(int ); void loadArray(STATS **array, int *c); void displayArray(STATS **array, int c); void saveArray(STATS **array, int count, int size); STATS **reloadArray(char *, int *count, int *size); main() { STATS** array = 0; int count = 0; int size = 500; char reloaded = 'N'; array = reloadArray(&reloaded, &count, &size); if(reloaded == 'N') array = makeArrayOfPointers(size); PAUSE; loadArray(array, &count); printf("** unSorted Array ** "); displayArray(array, count); //sortArray(array, count) printf("** Sorted by Age ** ");
  • 2. displayArray(array, count); saveArray(array, count, size); PAUSE; } // end of main void displayArray(STATS **array, int c) { int i; for (i = 0; i < c; i++) { printf("Record[%i] Age is %i.t Weight is %i.t Height is %i. ", i, array[i]->age, array[i]- >weight, array[i]->height); } PAUSE; } // end displayArray void loadArray(STATS **array, int *c) { int value; int counter = *c; for (*c; *c < (counter + 4); *c = *c + 1) { printf(" Information for person: %i ", (*c) + 1); array[*c] = calloc(1, sizeof(STATS)); printf("Enter age: "); scanf("%i", &value); array[*c]->age = value; printf("Enter weight: "); scanf("%i", &value); array[*c]->weight = value; printf("Enter height: "); scanf("%i", &value); array[*c]->height = value; } // end for } // end loadArray STATS *makeArrayOfPointers(int size) { STATS *result; result = malloc(sizeof(STATS*) * size); return result; } // end makeArrayOfPointers
  • 3. void saveArray(STATS **array, int count, int size) { FILE *ptr; int i; ptr = fopen("c:myBinFile.bin", "wb"); if (ptr == NULL) { printf("Could not open the file "); PAUSE; exit(-1); } // SAVE THE SIZE OF THE ARRAY fwrite(&size, sizeof(int), 1, ptr); // SAVE THE EFFECTIVE SIZE or COUNT fwrite(&count, sizeof(int), 1, ptr); // SAVE EACH NODE/ELEMENT in the ARRAY for (i = 0; i < count; i++) { fwrite(array[i], sizeof(STATS), 1, ptr); } // end for fclose(ptr); }// end saveArray STATS **reloadArray(char *result, int *count, int *size) { STATS **temp = 0; FILE *ptr; int i; *result = 'Y'; ptr = fopen("c:myBinFile.bin", "rb"); if (ptr == NULL) { printf("Could not open the file "); PAUSE; *result = 'N'; } else { // Reload the size of the array fread(size, sizeof(int), 1, ptr);
  • 4. // Create the Array of Pointers temp = makeArrayOfPointers(*size); // Reload the count or effective size variable fread(count, sizeof(int), 1, ptr); // Reload the nodes or elements of the array for (i = 0; i < *count; i++) { temp[i] = calloc(1, sizeof(STATS)); fread(temp[i], sizeof(STATS), 1, ptr); } } // end else fclose(ptr); return temp; }// end reloadArray Solution //Declare function prototype above main function void sortArray(STATS **array, int count); //call sortArray function in main fuction sortArray(array, count); //Write the function defination as fallows /*I have used Bubble sort technique to sort the array. The following code will sort the array in ascending order of age. In Bubble sort it checks the cosecutive elements of array and swaps the elements if first element is greater than second element. Keep checking elements till end so that the greatest element will move to last position of array. */ void sortArray(STATS **array, int count) { STATS **temp; int i,j; //No. of Iterations required for(i=0;iage > array[j+1]->age) { //swapping of array elements