One easy way to control how data is written to the file is to use fprintf
. This is identical to the printf
except that the first parameter is where the information will be written to.
Example:
FILE *ficheiro = fopen ("teste.txt","w");
struct televisao tv;
//preencher tv com os dados que interessam
fprintf (ficheiro,"%d,%d,%d,%d,%s\n",tv.id_guit, tv.precodia, tv.preco, tv.estado,tv.nome);
fclose (ficheiro);
In this example I used ,
as a separator, which acts as if creating a file csv
, however, the format in which the data is written to the file is entirely at your discretion.