I am trying to write some measured data to a file so I can process them later.
I have used the functions provided in the AN10123: How to write to a file during execution, and I have discovered that the file is correctly created and opened but when I try to write something to it using the _write function, it displays the data to mu console instead of writing it to the file.
I have also used the other approach and I have used the fopen and fwrite functions but the result was the same.
The odd thing is that I have used the exact same code about 3 mounts ago and it worked perfectly.
Any help is apreciated,
Ilie
Code: Select all
void writeFETmeasurement(){
printstrln("Saving data ...");
int destinationFile = _open("FET.txt", O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
if (destinationFile == -1){
printstrln ("Error: _open failed");
_exit(1);
}
char tempChar[50];
int tempInt;
for (int i=0; i<processingSize; i++){
tempInt = sprintf (tempChar, "%d %lld %lld \n", i, sumSamplesClean[i]/nr_measurements, sumSamplesCompressed[i]/nr_measurements);
if (_write(destinationFile, tempChar, tempInt)!=tempInt){
printstrln("Error: _write failed");
_exit(1);
}
}
if (_close(destinationFile)!=0){
printstrln("Error: _close failed");
_exit(1);
}
printstrln("Save compleate");
_exit(1);
}