Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:image text in transcribed

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Make A Database In Historical Studies

Authors: Tiago Luis Gil

1st Edition

3030782409, 978-3030782405

More Books

Students also viewed these Databases questions

Question

=+What kinds of problems need to be overcome?

Answered: 1 week ago

Question

=+Describe an important trade-off you recently faced

Answered: 1 week ago