-1
I’m starting in C and making a program that records some information (all this information goes to a file). each record has a registration number, starting with the record 0001. The problem is that I am trying to store the number of the last record made in another file, to know what will be the next registration number so that each time I register a complaint the number of the previous claim is the number + 1 link pro full code http://dontpad.com/codigoint
FILE *total;
numero_reclamacao = 1;
total = fopen("total.txt", "a+b");
if(total){
while(!feof(total)){
fscanf(total , "%d", &numero_reclamacao);//lendo o ultimo
} //n de reclamacao
}
else{
printf("ERRO");
}
numero_reclamacao += 1;//incrementando + 1
registrar(numero_reclamacao,outros parametros);//funcao que registra
fprintf(total, "%d", numero_reclamacao);//escrevendo no arquivo o último n de
//reclamacao usado
fclose(total);
what is happening is that whenever I register a complaint her number is 1, it never goes to 2, 3, 4, etc
If it is a text file why you specify binary (option b) in fopen?
– anonimo
it was just to test, but with or without the b I have the same problem
– Christian Fleury
first thing: fix code indentation...with sloppy indentation becomes more difficult to understand...plus the code is incomplete...not that it is to put 500 lines, but at least the full function, and/or the full main function would help more understanding
– zentrunix
What is the content of the file after at least one run?
– anonimo
link to full code http://dontpad.com/codigoint
– Christian Fleury
the contents of the file were to be 1 in the first run, 2 in the second, 3 in the third, etc
– Christian Fleury
I did not ask what was to be but rather the actual contents of the file after some executions.
– anonimo
stays always what was already there, if I put 10, will always register the complaint 10 and will never record 11 in the file, if there is nothing in the file gets always 0, never increases
– Christian Fleury