Assignment #0: Programming in C and Pointers
The goal of this assignment is to write a global function that prompts the
user to enter an unknown number of integers, and then read the integers until an invalid (non-integer)
entry is detected. The numbers are stored in an array and returned.
Then provide a main routine that calls your global function and prints the contents.
-
First do this in C++, using a vector. This should be relatively
easy coding.
-
Next, examine pg 213 and Figure 11.5 to see how this would be done in C++
using the base language arrays instead of the library vector
class. Observe that additional work must be done to pass to the user
the number of items read, and also, arrays have to be allocated via
new[] and released via delete[]. Pretty messy stuff.
-
Rewrite the code in Figure 11.5 to use C. Make sure your source code ends
in a .c suffix, so that only legal C is accepted. Among other
issues, you will
- Need to change the signature of getInts to simulate call
by reference.
- Use malloc instead of new[]. Remember to allocate the correct number of bytes.
- Use free instead of delete[].
- Use printf and scanf.
- Move some declarations.