I'm back with another C question, I'm afraid.
This time, I'm having issues with error handling. As far as I can tell, the only error handling that exists in C is longjmp and setjmp. As I understand it, using these involves setting a program state, then later giving you the option to return to that program state, One would use this to handle errors by checking if the inputs for a function are valid before calling it, and restoring the program state that was chosen originally. The use of this method requires you to be able to determine if the inputs for a function are valid without actually calling it.
In my situation, I am attempting to read values from a csv as numbers, do some math and put the result into another csv. Unfortunately, some of the files contain values in the entry that cannot be read properly. This causes errors. Here's the relevant snippet of the code:
ptr_pricelist = fopen(pricepath,"r");
fgets(buf,1024,ptr_pricelist); //load up the header of the file
fgets(buf,1024,ptr_pricelist); //look past the header to the second line
//We want the values in the 5th column
strtok(buf,",");
strtok(NULL,",");
strtok(NULL,",");
strtok(NULL,",");
strcpy(value,strtok(NULL,",")); //This is where the errors happen
oldprice=atof(value);
Is there any way handle these errors? I can't use the longjmp/setjmp method, because I don't know how to check whether the code in question will cause errors without actually running it.