How I can write a EOF?

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

How I can write a EOF?

Jump to solution
1,394 Views
soli
Contributor I

Hello,

 

I initialize the io-driver for memory with this code. That works well:

 

 

uint8_t memory [4000]; uint32_t mem_init (void){    MQX_FILE_PTR    drive_p        = NULL;    _mqx_uint       error_code      = 0;     if ( (error_code = _io_mem_install(NAME_OF_FILE, memory, sizeof(memory))) == MQX_OUT_OF_MEMORY)                               {                                               printf("could not install drive\n");                                               return 1;                               }     //!____Open_the_drive______________________________________________________    drive_p = _io_fopen( NAME_OF_FILE, "r");    if (drive_p == NULL )    {        printf("unable to open %s\n", NAME_OF_FILE);        return 1;    }   //!___close________________________________________________________________    _io_fclose(drive_p);    return 0;}

 

 

 

After that, I open again with:

pDataFile  = fopen(NAME_OF_FILE, "w+");

 

 

and write some lines with:

fprintf(pDataFile, "%s\n", buffer);

 

 

Until this point everything works well. Now I read out all lines until the function “_io_fgetline()” receive “IO_EOF”. But I get much more (empty) lines as I have written before.

 

Why the driver does not set the EOF automatically?

Can I set explicit the “End Of File”?

 

Thank you for response.

 

0 Kudos
1 Solution
504 Views
DavidS
NXP Employee
NXP Employee

Hello,

I think if after the fprintf() call you do a fflush() it will help.

I've seen other post where once you write to file, then fclose(), then re open.

Regards,

David

View solution in original post

0 Kudos
4 Replies
504 Views
c0170
Senior Contributor III

Hello nico,

fprintf returns number of bytes written. Check return value of fprintf and afterwards read written characters back from file and compare if numbers are equal.

As david pointed out, fflush also might help to write remaining unwritten data if this situation happened in your case.

If any of these help, get back to us with code snippet what we actually can test.

Regards,

MartinK

0 Kudos
505 Views
DavidS
NXP Employee
NXP Employee

Hello,

I think if after the fprintf() call you do a fflush() it will help.

I've seen other post where once you write to file, then fclose(), then re open.

Regards,

David

0 Kudos
504 Views
soli
Contributor I

Noone can help?

 

0 Kudos
504 Views
Monica
Senior Contributor III

Nico!

Thanks for your patience, and apologizes for the delay.

Out technicians will be shortly addressing your questions!

Regards!

Monica

0 Kudos