Access violation reading location

Joined
Oct 23, 2022
Messages
1
Reaction score
0
Hi folks,

In my C code, I made my program read data from a CSV file. However, I am not sure why I get the Access violation reading location error.
Part of my code is set for reading the CSV file. I have denoted where my code stops. Any help is appreciated.

*******************************************************

#define rowNum 44 //number of rows in the Input Excel file

struct csvTable
{
double SRBcol1[rowNum]; //Total columns in excel sheet
double SRBcol2[rowNum];
double SRBcol3[rowNum];
double SRBcol4[rowNum];
double SRBcol5[rowNum];
double SRBcol6[rowNum];
double SRBcol7[rowNum];
double SRBcol8[rowNum];
double SRBcol9[rowNum];
double SRBcol10[rowNum];



};

// Declare table
struct csvTable SRBtable[rowNum];

// Load file
ptrin = fopen("SRBinput.csv", "r");


if (ptrin == NULL)
{
printf("Couldn't open SRBinput file\n");
return 0;
}

for (int counter = 0; counter < rowNum; counter++)
{
char Sentry[100];
fgets(Sentry, 100, ptrin);

double* SRBcol1 = strtok(Sentry, ",");
double* SRBcol2 = strtok(NULL, ",");
double* SRBcol3 = strtok(NULL, ",");
double* SRBcol4 = strtok(NULL, ",");
double* SRBcol5 = strtok(NULL, ",");
double* SRBcol6 = strtok(NULL, ",");
double* SRBcol7 = strtok(NULL, ",");
double* SRBcol8 = strtok(NULL, ",");
double* SRBcol9 = strtok(NULL, ",");
double* SRBcol10 = strtok(NULL, ",");



if (SRBcol1 != NULL && SRBcol2 != NULL && SRBcol3 != NULL && SRBcol4 != NULL && SRBcol5 != NULL && SRBcol6 != NULL && SRBcol7 != NULL && SRBcol8 != NULL && SRBcol9 != NULL && SRBcol10 != NULL)
{
strcpy(SRBtable[counter].SRBcol1, SRBcol1);
strcpy(SRBtable[counter].SRBcol2, SRBcol2); *********//STOPS HERE************
strcpy(SRBtable[counter].SRBcol3, SRBcol3);
strcpy(SRBtable[counter].SRBcol4, SRBcol4);
strcpy(SRBtable[counter].SRBcol5, SRBcol5);
strcpy(SRBtable[counter].SRBcol6, SRBcol6);
strcpy(SRBtable[counter].SRBcol7, SRBcol7);
strcpy(SRBtable[counter].SRBcol8, SRBcol8);
strcpy(SRBtable[counter].SRBcol9, SRBcol9);
strcpy(SRBtable[counter].SRBcol10, SRBcol10);
}
else
{
strcpy(SRBtable[counter].SRBcol1, "\0");
strcpy(SRBtable[counter].SRBcol2, "\0");
strcpy(SRBtable[counter].SRBcol3, "\0");
strcpy(SRBtable[counter].SRBcol4, "\0");
strcpy(SRBtable[counter].SRBcol5, "\0");
strcpy(SRBtable[counter].SRBcol6, "\0");
strcpy(SRBtable[counter].SRBcol7, "\0");
strcpy(SRBtable[counter].SRBcol8, "\0");
strcpy(SRBtable[counter].SRBcol9, "\0");
strcpy(SRBtable[counter].SRBcol10, "\0");
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,516
Members
44,991
Latest member
Josephnag

Latest Threads

Top