I have code to sort 60000 lines into arrays for each data type
It worked for 1 line but when looping through many lines I get stack overflow error.
This is how I defined structs.
int main(void) {
typedef struct values{
struct values* Time;
struct values* RESP;
struct values* PLETH;
struct values* II;
struct values* V;
struct values* AVR;
struct values* ABP;
}values;
values array[60000];
Here is a sample of the data file
Here is the code I used to read the file.
char line[80];
FILE* pointer = fopen("bidmc_04_Signals.csv", "r");
fgets(line, 60000, pointer);//moves pointer past 1st line
printf(line);
fgets(line, 60000, pointer);
printf(line);
Here is the array generation part of my code
int i = 0;
int c = 0;
int row_count = 0;
int row_limit = 60000;
while (row_count < row_limit) {
fgets(line, 60, pointer);
char*p = strtok(line, ",");
c = 0;
while (p != NULL)
{
if (c == 0)
strcpy(array[i].Time, p);
array[i].Time = malloc(10000);
if (c == 1)
strcpy(array[i].RESP, p);
array[i].RESP = malloc(10000);
if (c == 2)
strcpy(array[i].PLETH, p);
array[i].PLETH = malloc(10000);
if (c == 3)
strcpy(array[i].II, p);
array[i].II = malloc(10000);
if (c == 4)
strcpy(array[i].V, p);
array[i].V = malloc(10000);
if (c == 5)
strcpy(array[i].AVR, p);
array[i].AVR = malloc(10000);
if (c == 6)
strcpy(array[i].ABP, p);
array[i].ABP = malloc(10000);
p = strtok(NULL, ",");
c++;
}
row_count++;
i++;
}
fclose(pointer);
for (i = 0; i < 60000; i++) {
free(array[i].RESP);
free(array[i].PLETH);
free(array[i].II);
free(array[i].V);
free(array[i].AVR);
free(array[i].ABP);
}
}
As you can see I tried using malloc() to move array data to heap but it didn't work. How do I prevent the code from getting a stack overflow error?