Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- i decided to get rid of the resizeArr() and just call the whole thing here
- void populateArr(int arr[], int* i, int *allocated) {
- int val = 0;
- /* loop until the user enters -999 */
- scanf("%d", &val);
- while (val != -999) {
- arr[*i] = val;
- (*i)++;
- if (isFull(*allocated, *i)) {
- int* temp = (int*) malloc(*allocated * sizeof(int));
- makeArrayCopy(arr, temp, *allocated);
- *allocated *= 2;
- free(arr);
- arr = temp;
- }
- /* get next value */
- scanf("%d", &val);
- }
- }
- // get rid of both scanf
- // clean up the array increment
- void populateArr(int arr[], int* i, int *allocated) {
- int val;
- while (1) {
- scanf("%d", &val);
- if (val == -999) break;
- arr[(*i)++] = val;
- if (isFull(*allocated, *i)) {
- int* temp = (int*) malloc(*allocated * sizeof(int));
- makeArrayCopy(arr, temp, *allocated);
- *allocated *= 2;
- free(arr);
- arr = temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement