I want to insert multiple lines in a .txt file and read the entire .txt file to validate the inserts, the problem is that it always shows me only one line. I insert text into a function and I send it to call many times.
This is my function to insert text:
int escribirEnArchivo(string texto)
{
char in[20 + 1] = {0};
char out[80 + 1] = {0};
char str[400] = {0};
FILE *file;
memset(in, 0, sizeof(in));
memset(out, 0, sizeof(out));
memset(str, 0, sizeof(str));
strcpy(in, texto.c_str());
file = fopen("Prueba.txt", "a");
fputs((char*)in, file);
fclose(file);
file = fopen("Prueba.txt", "r");
fgets(out, 80, (FILE*)file);
fclose(file);
cout<<out<<endl;
return 1;
}
Always print only: 1|Hola Mundo!|25.00|true
This function calls the insert several times:
int foo()
{
escribirEnArchivo("1|Hola Mundo!|20.00|true");
escribirEnArchivo("2|Adios Mundo!|50.00|false");
escribirEnArchivo("3|Hola Mundo!|75.00|true");
}