Guest User

Untitled

a guest
Sep 12th, 2019
93
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. i decided to get rid of the resizeArr() and just call the whole thing here
  2.  
  3. void populateArr(int arr[], int* i, int *allocated) {
  4. int val = 0;
  5. /* loop until the user enters -999 */
  6. scanf("%d", &val);
  7. while (val != -999) {
  8. arr[*i] = val;
  9. (*i)++;
  10. if (isFull(*allocated, *i)) {
  11. int* temp = (int*) malloc(*allocated * sizeof(int));
  12. makeArrayCopy(arr, temp, *allocated);
  13. *allocated *= 2;
  14. free(arr);
  15. arr = temp;
  16. }
  17. /* get next value */
  18. scanf("%d", &val);
  19. }
  20. }
  21.  
  22.  
  23. // get rid of both scanf
  24. // clean up the array increment
  25. void populateArr(int arr[], int* i, int *allocated) {
  26. int val;
  27. while (1) {
  28. scanf("%d", &val);
  29. if (val == -999) break;
  30. arr[(*i)++] = val;
  31. if (isFull(*allocated, *i)) {
  32. int* temp = (int*) malloc(*allocated * sizeof(int));
  33. makeArrayCopy(arr, temp, *allocated);
  34. *allocated *= 2;
  35. free(arr);
  36. arr = temp;
  37. }
  38. }
  39. }
RAW Paste Data