Write a C program that creates the dynamically alocated list holding strings with different size. Problem 1: To warm up, declare a double pointer to char variable and set it to NULL. Then, declare an integer el Nr that holds the number of element in the list and set it to 3. Using malloc function allocate a memory block your list to hold 3 items. Now, you need to add the first item (a string) to the list. Check the length of the string you want to add, and allocte a memory block to hold this string, using the malloc function. Remember, to include the space for the end-of-line character. Copy your string to the allocated memory block using strcpy function. Perform the same steps to add two more items. Problem 2: Create a function print_list which prints all elements in the list. Problem 3: Now, you will add automatically the elements to your list. Declare an integer el Nr that holds the number of element in the list, and initiate it with 0. Using malloc function allocate a memory block your list to hold a single item. Create a function add item which adds a new string, passed as an argument, to your list. This function should increase el Nr by one, each time it is invoked, and reallocate the memory block for your list with a new size, using realloc function. Then, allocate the memory block for the string you want to add (the last element of the expanded list), using malloc function. Finally, copy the string you want to add to the allocated memory block, using strcpy function.
Write a C program that creates the dynamically alocated list holding strings with different size. Problem 1: To warm up, declare a double pointer to char variable and set it to NULL. Then, declare an integer el Nr that holds the number of element in the list and set it to 3. Using malloc function allocate a memory block your list to hold 3 items. Now, you need to add the first item (a string) to the list. Check the length of the string you want to add, and allocte a memory block to hold this string, using the malloc function. Remember, to include the space for the end-of-line character. Copy your string to the allocated memory block using strcpy function. Perform the same steps to add two more items. Problem 2: Create a function print_list which prints all elements in the list. Problem 3: Now, you will add automatically the elements to your list. Declare an integer el Nr that holds the number of element in the list, and initiate it with 0. Using malloc function allocate a memory block your list to hold a single item. Create a function add item which adds a new string, passed as an argument, to your list. This function should increase el Nr by one, each time it is invoked, and reallocate the memory block for your list with a new size, using realloc function. Then, allocate the memory block for the string you want to add (the last element of the expanded list), using malloc function. Finally, copy the string you want to add to the allocated memory block, using strcpy function.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Write a C program that creates a dynamically allocated list holding strings with different sizes.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 7 steps with 4 images
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY