I'm using fscanf to read some values from a CSV file and I want to ensure that the data read into the values will not be too large and cause a buffer overflow.
My csv file has the format int,string,string and my code to read is below (I will fix the while condition later):
while(fscanf(f, "%d,%[^,],%[^,]", &inArray[i].ID, inArray[i].label, inArray[i].brand)/*insert while condition here*/
When using scanf I would specify the length like so to prevent overflow: scanf("%20f", example);
But if I try the same with the above: while(fscanf(f, "%d,%20[^,],%10[^,]", &inArray[i].ID, inArray[i].label, inArray[i].brand)/*insert while condition here*/
I get a crash when the code executes.
i? - Hulk