Question: **This must be coded in C, not C# or C++ ***Hi there I have coded this program already but I am unsure of how to

**This must be coded in C, not C# or C++ ***Hi there I have coded this program already but I am unsure of how to do the next step. Here is the procedure:

**This must be coded in C, not C# or C++ ***Hi thereAnd here is my code:

#include

#include

#include

//prototype for the function that sorts names and ages

void sortInputData(char name[20][100], int age[20], int numberEntries, char lastName[20][100]);

//prototype for the function that prints the instructions and scans the data from the user

void inputData(void);

// prototype for the function that prints the output

void printOutput(void);

//global variables: - (Professor Canon, I know we talked about this and these are not to be used in this class but I for the life of me could not figure out how to pass these arrays to my functions. I had to research and this is the best I could come up with!)

//holds names

char name[20][100];

//holds last names

char lastName[20][100];

//holds ages

int age[20];

//holds number of entries

int numberEntries = 0;

//variable for clearing input buffer

int c = 0;

int main()

{

//call to function inputData that prints the initial instructions as well as takes all input data

inputData();

//call to function printOutput that prints the data in alphebetical order (with respect to the first name of the people)

printOutput();

return 0;

}

//function inputData to execute - takes all input data and stores in variables accordingly:

void inputData()

{

// print initial instructions to user

printf("Please enter the number of people you wish to enter into the database: ");

// scan how many entries user wishes - store in numberEntries

scanf("%d", &numberEntries);

// loop for how ever many entries user decided on

for (int i = 0; i

{

// clears out the input buffer each loop

while ((c = getchar()) != ' ')

{

}

//print instructions to the user

printf(" For person #%d: ", i + 1);

printf("Enter name: ");

//scans name into array name

scanf("%s", name[i]);

printf("Enter last name: ");

//scans lastName into array lastName

scanf("%s", lastName[i]);

printf("Enter age: ");

//scans age into array age

scanf("%d", &age[i]);

}

//call to the function sortInputData

sortInputData(name, age, numberEntries, lastName);

}

//function printOutput to execute

void printOutput()

{

printf(" ****Here are the sorted names**** ");

for (int i = 0; i

{

// print the user names and ages

printf("name: %s ", name[i]);

printf("last name: %s ", lastName[i]);

printf("age: %d ", age[i]);

}

}

//function sortInputData to execute - takes with it the following variagbles:

void sortInputData(char name[20][100], int age[20], int n, char lastName[20][100])

{

//char array s and int t to use for copying over

char s[100];

char a[100];

int t;

for (int i = 0; i

{

for (int j = i + 1; j

{

if (strcmp(name[i], name[j]) > 0)

{

//switch the names:

strcpy(s, name[i]);

strcpy(name[i], name[j]);

strcpy(name[j], s);

//switch the order of the age:

t = age[i];

age[i] = age[j];

age[j] = t;

strcpy(a, lastName[i]);

strcpy(lastName[i], lastName[j]);

strcpy(lastName[j], a);

}

}

}

}

I will for sure thumbs up your help!!!

Part II Implement the exact same problem in an array of structures that contains the first name, last name and age. Allow it to input the data, sort the data, and then print the results

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!