I have an integer array that is dynamically allocated by the following:
int *ranArr(int size) {
int *arr= malloc(size *sizeof(int));
for(int i = 0; i < size; i++) {
arr[i] = genRan(size);
}
return arr;
}
I want to dynamically allocate memory for a string that I will convert my integer array into and store it in the string:
int *arrayCopy = ranArr(size);
int arrayCopyLen = size;
char *arrayString= (char*) malloc(size * sizeof(char));
int index = 0;
for(int i = 0; i< arrayCopyLen ; i++) {
index += sprintf(&arrayString[index], "%d ,", arrayCopy[i]);
}
int arrayStringLen = strlen(arrayString)+1;
This works for array sizes around 1000 but when I set the size to 2000 or so it breaks and I get a segmentation fault.
arrString? it's not defined in your codegenRan?