I am in my internship and Im a working on a projet of SLAM simulation, and I'm having a little problem while writing my cloud points into my file.
Here is my code, I have two functions :
void ecriture_fichier(double x, double y){
FILE *fichier = NULL;
fichier = fopen("/home/stagiairepierrick/points/points.txt", "a");
if(fichier != NULL ){
fprintf(fichier, "%lf %lf \n",x,y);
} else {
std::cerr << "probleme ecriture" << std::endl;
}
fclose(fichier);
}
void ajout_nombre_lignes(long nombre_lignes){
FILE *fichier = NULL;
fichier = fopen("/home/stagiairepierrick/points/points.txt", "r+");
if(fichier != NULL ){
fseek(fichier, 0, SEEK_SET);
fprintf(fichier, "%ld \n", nombre_lignes);
} else {
std::cerr << "probleme ecriture nombre de lignes" << std::endl;
}
fclose(fichier);
}
The function ajout_nombre_ligne
is called just before ecriture_fichier
.
I want the first lign to be the number of ligne (variable nombre_lignes
), however when I execute this code, I get the following result in my file:
8070
00000 5.200000
5.200000 5.200000
5.200000 5.200000
5.200000 5.200000
5.200000 5.200000
5.200000 5.200000
For each char added on my first line, I can see that one my char of the second line is being removed, I understand why but I can't find any solution.
Could you guys help me?