Reading txt file on k60 MQX

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reading txt file on k60 MQX

903 Views
Curro
Contributor III

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

0 Kudos
3 Replies

651 Views
Curro
Contributor III

I tried even with this instruction

 

fread(&prec,sizeof(DB_DATA),1,fp)

 

but I get the same problem.

 

Any idea?

Thanks

 

0 Kudos

651 Views
michele_novalia
Contributor III

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?

0 Kudos

651 Views
Curro
Contributor III

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...?

0 Kudos