Question: home / study / engineering / computer science / computer science questions and answers / complete the program to perform the following tasks, see attached

home / study / engineering / computer science / computer science questions and answers / complete the program to perform the following tasks, see attached .c source file. the sample ...

Question: Complete the program to perform the following tasks, see attached .c source file. The sample prog...

Complete the program to perform the following tasks, see attached .c source file.

The sample program is completed for int types, complete the program by adding functionality for doubles and characters.

Create three pointers of size 0, one each for integers, doubles, and characters

Prompt the user for which type of data they will enter (integer, double, character)

Reallocate the amount of memory that pointer has and add the new value to it

Print all three pointers and loop until the user chooses to exit

Complete this in C programming

Attached File:

#include  #include  //Function Prototypes void addInt(int **intPtr, int *intCount); // add prototypes for char and double here void printInts(int *intPtr, int intCount); // add prototypes for char and double here int main(){ //Keep track of the number of each type entered as well as the user's choice for each iteration of the main loop int intCount = 0, dblCount = 0, chrCount = 0, userChoice = 0; //Create our pointers initially with no memory allocated to them int *intPtr = (int *)malloc(sizeof(int) * 0); //Loop until the user chooses to exit while (userChoice != 4){ //Retrieve input from user printf(" Which value will you add? 1. Integer 2. Double 3. Character 4. Exit "); scanf("%d%*c", &userChoice); //Call different functions based on the user's choice switch (userChoice){ case 1: //Add an integer to the int pointer addInt(&intPtr, &intCount); break; case 2: //Add a double to the dbl pointer // function call to addDouble break; case 3: //Add a character to the chr pointer //function call to addCharachter break; default: printf(" Program Complete! "); break; } //Print all three pointers at the end of every iteration printInts(intPtr, intCount); // print the double pointer // print the charachter pointer printf(" "); } free(intPtr); // free double pointer // free charachter pointer getchar(); return 0; } //Function to add a value to the int pointer and increment the amount of values in the pointer void addInt(int **intPtr, int *intCount){ int value; printf("Enter your value: "); scanf("%d%*c", &value); //Dereference and increment our intCount (*intCount)++; //Dereference and reallocate memory to our intPtr (*intPtr) = realloc((*intPtr), sizeof(int) * (*intCount)); //Store the entered value into the proper position of our intPtr (*intPtr)[(*intCount) - 1] = value; } //Function to add a value to the dbl pointer and increment the amount of values in the pointer void addDbl(double **dblPtr, int *dblCount){ // complete the function to addDdbl } //Function to add a value to the chr pointer and increment the amount of values in the pointer void addChr(char **chrPtr, int *chrCount){ // complete function to add charachter } //Print our integer pointer void printInts(int *intPtr, int intCount){ int i = 0; printf(" Ints: "); for (i = 0; i < intCount; i++){ printf("%d ", intPtr[i]); } } //Print our double pointer void printDbls(double *dblPtr, int dblCount){ // complete function to print a double pointer } } //Print our character pointer void printChrs(char *chrPtr, int chrCount){ // complete function to print a charachter pointer } } 

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!