EOF will be ignored RRS feed

  • Question

  • Hello, I am new to C++ and I have to do a project with files, but I seem to have a problem with EOF.

    The program is supposed to add lines and articles to the .txt list until CTRL^Z is pressed, but after I do that, it will not end. I will be prompted to continue to add the next line/article.

    Is there a setting I do not know about? 


    #include <stdio.h>
    typedef struct {
    int cod;
    char denumire[20];
    float pret_mediu;
    int cant[12];
    } PRODUS;
    void main()
    FILE* f;
    PRODUS x;
    char nume_fisier[20];
    int i;
    printf("\n\nNumele fisierului: ");
    if (!(f = fopen(nume_fisier, "wb"))) printf("\n\nNu poate fi creat fisierul cu numele %s",nume_fisier);
    printf("\nCod produs: ");
    scanf("%d", &x.cod);
    //---initial operations end here---
    while (!feof(stdin))
    //---editing article---
    printf("Denumire produs: ");
    printf("Pret mediu: ");
    scanf("%f", &x.pret_mediu);
    printf("Cantitate lunara:\n");
    for (i = 0; i<12; i++)
    printf(" - luna %d: ", i + 1);
    scanf("%d", &x.cant[i]);
    fwrite(&x, sizeof(PRODUS), 1, f);
    //---article editing ends here---
    printf("\nCod produs: ");
    scanf("%d", &x.cod);

    Saturday, March 17, 2018 2:01 PM


  • Hello MistHunter,

    As it seems you are looking for a C++ forum not a C# forum. You should repost your question somewhere here.

    • Marked as answer by MistHunter Saturday, March 17, 2018 2:33 PM
    Saturday, March 17, 2018 2:21 PM

All replies