I'm running a program that opens a .csv file that contains 3 different (float) values on each line. I want to separate the different values in different variables. For that I have already used strtod() funcion but it only works on Visual Studio and not on DAVE IDE (based on Eclipse). I have also tested the following code but with no success at all (it recognizes a lot of garbage and nothing similar to want I want).
f_read(&fil, &buff2[0], 25, &br);
f_close(&fil);
for (int y=0; y<25; y++){
if ((buff2[y] == '\n') || (buff2[y] == '\r')){
break;
}
else count++;
}
for (int y=0; y<count; y++){
cut[y] = buff2[y];
}
for (int y=count; y<25; y++){
cut[y] = NULL;
}
//token = strtok(cut, ";");
/* walk through other tokens */
/*while( token != NULL )
{
array[j] = atof(token);
token = strtok(NULL, ";");
j++;
}*/
for (int j = 0, ptr = cut; j < 3; ++j, ++ptr)
{
//array[j] = (float)strtof(ptr, &ptr);
array[j] = (double)strtod(ptr, &ptr);
}
The commented parts of the code are other tests I've made but none of those work. And the reason why I've used f_read() is because I only can use this library: http://elm-chan.org/fsw/ff/00index_e.html
An example of "cut" string is bellow:
cut[0] char 52 '4'
cut[1] char 46 '.'
cut[2] char 50 '2'
cut[3] char 49 '1'
cut[4] char 54 '6'
cut[5] char 59 ';'
cut[6] char 48 '0'
cut[7] char 59 ';'
cut[8] char 49 '1'
cut[9] char 48 '0'
cut[10] char 48 '0'
cut[11] char 0 '\0'
cut[12] char 0 '\0'
cut[13] char 0 '\0'
cut[14] char 0 '\0'
cut[15] char 0 '\0'
cut[16] char 0 '\0'
cut[17] char 0 '\0'
cut[18] char 0 '\0'
cut[19] char 0 '\0'
cut[20] char 0 '\0'
cut[21] char 0 '\0'
cut[22] char 0 '\0'
cut[23] char 0 '\0'
cut[24] char 0 '\0'
After the 11th element there's nothing, but that's not the point since this is only an example and some of the lines on the .csv file have more digits (but they have the same 3 variables).
Thanks in advance.
EDIT: Problem solved! It seems that DAVE IDE doesn't like to include an headder with includes. I had to write #include in the beggining of main.c.