Write a program that reads an unknown number of integers (int16_t) from the keyboard, terminated when the value (-10000) is given, and stores these into a dynamically sized array. The array should be initialised with a size to hold 10 values, and should increase in size by steps of 10 values whenever the array needs to be resized. (Note that the array should always have capacity to hold another value, for example, when it is holding 10 values the array size should be 20; the next step size up). Once it reads -10000, the program should print how many numbers it read in the format Numbers read = , then exit. The program must free() the array before exiting (but after printing the how many numbers have been read). You can use scanf("%hd", &number) to read a 16 bit integer. Note: because of the way we test this, you must not call realloc() if you just read in -10000; be efficient! For example: Input 1 2 3 4 5 -10000 Result _TESTALLOC: (calloc) Add block 0, total memblks 20 _TESTALLOC: (calloc) Total number of allocations 1, total memblks 20 Numbers read = ! _TESTALLOC: (free) Free block 0, total memblks 20 _TESTALLOC: (free) Total number of allocations 1, total memblks 0 _TESTALLOC: Total number of allocations made 1, total outstanding memblks 0

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...
icon
Related questions
Question
Write a program that reads an unknown number of integers (int16_t) from the keyboard, terminated when the value (-10000) is given, and stores these into a dynamically sized array.
The array should be initialised with a size to hold 10 values, and should increase in size by steps of 10 values whenever the array needs to be resized. (Note that the array should always have capacity to hold
another value, for example, when it is holding 10 values the array size should be 20; the next step size up).
Once it reads -10000, the program should print how many numbers it read in the format Numbers read = <n>, then exit. The program must free() the array before exiting (but after printing the how many
numbers have been read).
You can use scanf("%hd", &number) to read a 16 bit integer.
Note: because of the way we test this, you must not call realloc() if you just read in -10000; be efficient!
For example:
Input
1 2 3 4 5 -10000
Result
_TESTALLOC: (calloc) Add block 0, total memblks 20
_TESTALLOC: (calloc) Total number of allocations 1, total memblks 20
Numbers read = 5
_TESTALLOC: (free) Free block 0, total memblks 20
_TESTALLOC: (free) Total number of allocations 1, total memblks 0
_TESTALLOC: Total number of allocations made 1, total outstanding memblks 0
Transcribed Image Text:Write a program that reads an unknown number of integers (int16_t) from the keyboard, terminated when the value (-10000) is given, and stores these into a dynamically sized array. The array should be initialised with a size to hold 10 values, and should increase in size by steps of 10 values whenever the array needs to be resized. (Note that the array should always have capacity to hold another value, for example, when it is holding 10 values the array size should be 20; the next step size up). Once it reads -10000, the program should print how many numbers it read in the format Numbers read = <n>, then exit. The program must free() the array before exiting (but after printing the how many numbers have been read). You can use scanf("%hd", &number) to read a 16 bit integer. Note: because of the way we test this, you must not call realloc() if you just read in -10000; be efficient! For example: Input 1 2 3 4 5 -10000 Result _TESTALLOC: (calloc) Add block 0, total memblks 20 _TESTALLOC: (calloc) Total number of allocations 1, total memblks 20 Numbers read = 5 _TESTALLOC: (free) Free block 0, total memblks 20 _TESTALLOC: (free) Total number of allocations 1, total memblks 0 _TESTALLOC: Total number of allocations made 1, total outstanding memblks 0
Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY