SlideShare a Scribd company logo
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 .pdf
ezzi552
 
An imperative study of c
An imperative study of cAn imperative study of c
An imperative study of c
Tushar B Kute
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
Han 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.pdf
herminaherman
 
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
fsenterprises
 
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
Eleanor McHugh
 
week-16x
week-16xweek-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)
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.docx
cgraciela1
 
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
arri2009av
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
Srikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
Srikanth
 
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
manojmozy
 
Programming in C
Programming in CProgramming in C
Programming in C
nagathangaraj
 
C
CC
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
Kevlin 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.pdf
fashiongallery1
 
c programming
c programmingc programming
c programming
Arun Umrao
 
#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
anandatalapatra
 
#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
gertrudebellgrove
 

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
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C
CC
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.pdf
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 
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
badshetoms
 

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

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 

Recently uploaded (20)

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 

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