Hi all,
I want to open .csv file and read the cell entries in column A and B as shown in the attached image, sample1.jpg and put in the arrays. But the program must be able to detect empty rows (row 29, 32, 34 and 38 as shown in the attached image) for processing other thing.
I know how to do it for text file. Below is my code
Code:
void main(void)
{
uint64 array1[1000];
uint64 array2[1000];
uint64 index;
char line[1000];
char *token;
char *breaks = " \t\n";
uint64 totalEntries = 0;
uint64 i=0;
uint64 j=0;
FILE *fstream = fopen("MCMT10.txt","r");
if(fstream == NULL)
{
printf("\n file opening failed ");
}
while(fgets(line, 1000, fstream) != NULL)
{
if(strlen(line)>2)
{
token = strtok(line, breaks);
// skip empty lines
if (token != NULL)
{
if(token != NULL)
{
array1[i] = Atoi64(token, 16);
i++;
totalEntries++;
}
token = strtok(NULL, breaks);
if(token != NULL)
{
array2[j] = Atoi64(token, 16);
j++;
}
}
}
else
{
printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
i=0;
j=0;
printf("\n*********************************************");
}
}
fclose(fstream);
printf("\nTotal entries = %d", totalEntries);
}