Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <cstring>
  4.  
  5. struct FooArray {
  6. int* data;
  7. int len;
  8. };
  9.  
  10.  
  11. static int* numbers;
  12.  
  13. void repeat(int x, int countToAdd, FooArray& foo)
  14. {
  15. int finalAmount = foo.len + countToAdd;
  16. do
  17. {
  18. int y = x;
  19. foo.data[foo.len] = x;
  20. foo.len++;
  21. } while(foo.len < finalAmount);
  22. }
  23.  
  24. void setupNumbers(FooArray& inArry)
  25. {
  26.  
  27. inArry.len = 0;
  28. int arraySize = 12;
  29. inArry.data = static_cast<int *>(malloc(arraySize * sizeof(int)));
  30. memset(inArry.data, 0, sizeof(int) * arraySize);
  31.  
  32. repeat(5, 1, inArry);
  33. repeat(2, 2, inArry);
  34. repeat(8, 6, inArry);
  35. }
  36.  
  37. int main()
  38. {
  39. FooArray thing;
  40. setupNumbers(thing);
  41.  
  42. for (int i = 0; i < thing.len; i++) {
  43. printf("%d\n", thing.data[i]);
  44. }
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement