Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <cstring>
- struct FooArray {
- int* data;
- int len;
- };
- static int* numbers;
- void repeat(int x, int countToAdd, FooArray& foo)
- {
- int finalAmount = foo.len + countToAdd;
- do
- {
- int y = x;
- foo.data[foo.len] = x;
- foo.len++;
- } while(foo.len < finalAmount);
- }
- void setupNumbers(FooArray& inArry)
- {
- inArry.len = 0;
- int arraySize = 12;
- inArry.data = static_cast<int *>(malloc(arraySize * sizeof(int)));
- memset(inArry.data, 0, sizeof(int) * arraySize);
- repeat(5, 1, inArry);
- repeat(2, 2, inArry);
- repeat(8, 6, inArry);
- }
- int main()
- {
- FooArray thing;
- setupNumbers(thing);
- for (int i = 0; i < thing.len; i++) {
- printf("%d\n", thing.data[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement