I'm trying to run a code on k60 with MQX 3.6.2.
The code is tested on PC and everything is ok.
typedef struct
{
char dbver[20];
char marca[20];
char modello[20];
char dettaglio[20];
uint_32 gas;
char olio[10];
} DB_DATA;
.
.
.
FILE *fp;
DB_DATA prec,;
.
fp=fopen("a:/file.txt","r");
.
fscanf(fp,"%s%s%s%i%s",prec.marca,prec.modello,prec.dettaglio,&prec.gas,prec.olio);
Txt file is composed by rows so made:
name1 name2 name3 500 name4
with spaces (I tried even with tabs) between names/number.
In prec.marca I find all the line and program (of course...) goes in error.
Someone can help me?
Thanks and regards
I tried even with this instruction
fread(&prec,sizeof(DB_DATA),1,fp)
but I get the same problem.
Any idea?
Thanks
Hi,
I typically use:
fread( fileBuff, sizeof(U16), 1, filePtr );
without problem.
I could not understand what kind of problem are you having with fread?
At this moment I use this code and it's ok.
char RIGA[100];
char *str1;
.
.
.
fscanf(fp,"%s",RIGA);//read all row
fgetc(fp);
str1 = strtok(RIGA, " ");
strcpy(prec.marca,str1);
str1 = strtok(NULL, " ");
strcpy(prec.modello,str1);
str1 = strtok(NULL, " ");
strcpy(prec.dettaglio,str1);
str1 = strtok(NULL, " ");
strcpy(prec.gas,str1);
str1 = strtok(NULL, "\n");
strcpy(prec.olio,str1);
Nothing better than this...?