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.
已解决! 转到解答。
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