Problem with the if-lse

Asked

Viewed 91 times

0

I’m having a problem at the time of a comparison with the if-lse! I have a function that reads one file and writes to another only what is approved by if-Else, then deletes the first file and changes the name of the second one to have the name of the first one! it happens that when printing the new file comes out blank!

void copia_arquivo3(FILE *file1, FILE *file2, int codigo)
{
char confirma_nome_produt2[31];
float confirma_preco_produt2;
int confirma_codigo_produt2;
int confirma_quant_produt2;

 while (fscanf(file1, "%d %f %i %[^\n]s", &confirma_codigo_produt2, &confirma_preco_produt2, &confirma_quant_produt2, confirma_nome_produt2) != EOF)
{
    if (codigo != confirma_codigo_produt2)
    {
        fprintf(file2, "%d %.2f %i %s\n", confirma_codigo_produt2, confirma_preco_produt2, confirma_quant_produt2, confirma_nome_produt2);
    }
    else
    {
        fprintf(file2, "%d %.2f %i %s\n", confirma_codigo_produt2, confirma_preco_produt2, confirma_quant_produt2--, confirma_nome_produt2);
    }
}
fclose(file1);
fclose(file2);

remove("produtos\\produto.txt");
rename("produtos\\produto2.txt", "produtos\\produto.txt");}
  • 1

    Are you sure you want to record the quantity and only then decrease this amount?

  • Call confirma_quant_produt2-- is to call the later decrease. The decrease happens, but only after the value of the variable has been copied. The question is about php, but the concepts apply in C as well: https://answall.com/q/80383/64969

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.