Question: In c language Problem 1: Malloc and Realloc. Your job today is to create a program that takes in an arbitrary amount of data and

In c language

Problem 1: Malloc and Realloc. Your job today is to create a program that takes in an arbitrary amount of data and stores it into a correctly sized array. You will do this for 4 data types

Interger Double Character String

The user should be allowed to enter an infinite number of any of these data types. Your program should identify what data type was received, and then store it in the appropriate array. Make sure you dynamically allocate enough space for the array. The contents of all four arrays should be displayed after each input.

Example: Enter your input: 123

String list: Integer list: 123 Double List: Character list:

Enter your input: 7.5

String list: Integer list: 123 Double List: 7.5 Character list:

Enter your input: s

String list: Integer list: 123 Double List: 7.5 Character list: s

Enter your input: l.0.0

String list: 1.0.0 Integer list: 123 Double List: 7.5 Character list: s

Enter your input: Malloc is fun

String list: 1.0.0 Malloc is fun Integer list: 123 Double List: 7.5 Character list: s

Hints:

Lab #9

Use Integers to keep track of how many elements of each type you have (to use with realloc)

Before using realloc, you MUST malloc (even if you just malloc a size of 0)

Strings are arrays of characters(you will need to malloc a 2d array)

Break this problem into smaller parts tackle them one at a time

Problem 2

Take two arrays of ints in from the user. Make sure to dynamically allocate them. Compare these two lists to each other, and if you come across an element that is not in the other array, add it to it. Make sure to use realloc to increase the size of the array. Your input doesnt have to be in its own function, but if you do do so, make sure you pass the pointer by reference and deference accordingly.

Example input and output:In c language Problem 1: Malloc and Realloc. Your job today is

Enter as many numbers as you want for array 1, press q to quit Enter the 0th element: 1 Enter the 1th element: 2 Enter the 2th element: 3 Enter the 3th element: 4 Enter the 4th element: 5 Enter the 5th element: 6 Enter the 6th element: 7 Enter the 7th element: q Enter as many numbers as you want for array 1, press q to quit Enter the 0th element: 9 Enter the 1th element: 12 Enter the 2th element: 15 Enter the 3th element: q Position 0 is 1 and 9 Position 1 is 2 and 12 Position 2 is 3 and 15 Position 3 is 4 and 1 Position 4 is 5 and 2 Position 5 is 6 and 3 Position 6 is 7 and 4 Position 7 is 9 and 5

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!