I made a code to read .csv files. Every new line is after 'n' and every next element is after ','.the whole code is working fine to me, I get place(col and line) and I trying to change the value in this place by reading the whole file to array and than search the place with 'i' and trying to fseek that start from 'i' to change there only the needed value, but when I debug I found out that arr[i] (the chosen value), is not in the same place as fseek(csvfile,i,SEEK_SET) can someone tell me how I fseek the file pointer to the 'i' place to change the value??? thanks a lot
int changeValue(int line, int col, char str[],const char* path)
{
FILE* csvFile = fopen(path, "r+");
char arr[VERY_BIG_MEMORY];
int i = 0;
int ch = 0;
int q =0;
if (!csvFile)
{
printf("Can't read the filenPlease open a filen");
retu -1;
}
initarr(arr, VERY_BIG_MEMORY);
do
{
ch = fgetc(csvFile);
arr[i] = (char)ch;
i++;
} while (ch != EOF);
fseek(csvFile,0L, SEEK_SET);
i = 0;
q = 1;
while (q < line)
{
ch = arr[i];
if (ch == 'n')
{
q++;
}
i++;
}
q = 1;
while (q < col)
{
ch = arr[i];
if (ch == ',')
{
q++;
}
i++;
}
q = 0;
fseek(csvFile,i,SEEK_SET );
//ch = arr[i];
//ch = fgetc(csvFile);
/*while (str[q])
{
fputc(str[q], csvFile);
q++;
}*/
fclose(csvFile);
}
