I'm doing a program that basically takes a float, calculates a percentage under the value if you want to write, it will write the information in a txt to be incremented now (basically used as a database). The problem comes in the following aspect. When deleting the txt file and running the program (which verifies that the file exists, if it does not create it), the problem arises that after creation, there is a fprintf () that printed default values to be used, but nothing is printed on file up to 2 execution (the first of the error and closes the program, obviously). Code from inside the main of opening the file and creating it.
arq = fopen("dados.txt","r+");
if (arq == NULL){
arq = fopen("dados.txt","wb");
printf("Arquivo \"dados.txt\" inexistente!\nCriando novo arquivo.\n\n");
fprintf(arq, "Terreno %2.2f\n",Terreno);
fprintf(arq, "CNH %2.2f\n",CNH);
fprintf(arq, "Contas %2.2f\n",Contas);
fprintf(arq, "Poupança %2.2f\n",Poupanca);
fprintf(arq, "Lazer %2.2f\n",Lazer);
fprintf(arq, "Utilitários %2.2f\n",Utilitarios);
}
And now the final fscan () and fprintf code, which displays in the program.
printf("-==Exibição de valores armazenados==-\n");
printf("+----------------------+\n");
fscanf(arq, "%s %f", TextoAux, &AcmTerreno);
AcmTerreno += Terreno;
printf("|%s = %8.2f|\n", TextoAux,AcmTerreno);
fscanf(arq, "%s %f", TextoAux, &AcmCNH);
AcmCNH += CNH;
printf("|%s = %8.2f|\n", TextoAux,AcmCNH);
fscanf(arq, "%s %f", TextoAux, &AcmContas);
AcmContas += CNH;
printf("|%s = %8.2f|\n", TextoAux,AcmContas);
fscanf(arq, "%s %f", TextoAux, &AcmPoupanca);
AcmPoupanca += Poupanca;
printf("|%s = %8.2f|\n", TextoAux,AcmPoupanca);
fscanf(arq, "%s %f", TextoAux, &AcmLazer);
AcmLazer += Lazer;
printf("|%s = %8.2f|\n", TextoAux,AcmLazer);
fscanf(arq, "%s %f", TextoAux, &AcmUtilitarios);
AcmUtilitarios += Utilitarios;
printf("|%s = %8.2f|\n", TextoAux,AcmUtilitarios);
printf("+----------------------+\n");
fprintf(arq, "Terreno %2.2f\n",AcmTerreno);
fprintf(arq, "CNH %2.2f\n",AcmCNH);
fprintf(arq, "Contas %2.2f\n",AcmContas);
fprintf(arq, "Poupança %2.2f\n",AcmPoupanca);
fprintf(arq, "Lazer %2.2f\n",AcmLazer);
fprintf(arq, "Utilitários %2.2f\n",AcmUtilitarios);