Question: Edit the code so that it adheres to the instructions: Write a C program named enter _ ints.c . The program will allow the user
Edit the code so that it adheres to the instructions:
Write a C program named enterints.c The program will allow the user to enter as many ints as they want. It should first prompt the user for the number of ints that they will enter. It must then dynamically allocate exactly enough space for the ints using malloc. It should then allow the user to enter them on a single line or multiple lines It should then print the contents of the array. Then the memory should be freed. Compile enterints.c into an executable named enterints. Some example runs are shown below please match the output formatting exactly, note there is one space after the question mark and not a newline
Hint: You cannot use scanf, but you can use the getint function from of Kernighan, which is posted as getint.c in homemsarriscscilab to get started ie rename getint.c to be enterints.c then modify it
Hint: do not declare a fixedsize array such as int arraycount; You must use malloc.
Note: prior to Ceg in Kernighan book array sizes needed to be determinable at compile time.
Hint: The autograder will try to compile enterints.c only it assumes no additional c files are being used
$ enterints
How many numbers will you enter?
array
array
array
array
array
$ enterints
How many numbers will you enter?
array
array
array
array
enterint.c:
#include
#include
int getintint pn;
int main
int n i;
int array;
printfHow many numbers will you enter? ;
getint&n;
array int mallocn sizeofint;
if array NULL
printfMemory allocation failed.
;
exit;
for i ; i n; i
getint&arrayi;
for i ; i n; i
printfarraydd
i arrayi;
freearray;
return ;
int getintint pn
int c sign;
while c getchar c
;
sign c : ;
if c c
c getchar;
for pn ; c && c ; c getchar
pn pnc ;
pn sign;
if c EOF
ungetcc stdin;
return c;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
