0

This is the code. I apologize if I asked obvious questions

int main()
{
    int stat;
    char v_id[100], c_id[100], line[BUFFER_SIZE], tos[100], cust_stat[100], n_daysasd[100], tot_fee[100];;
    printf("Enter Visitor ID: ");
    scanf("%s", &v_id);
    printf("Enter Customer ID: ");
    scanf("%s", &c_id);
    FILE* fptr2;
    FILE* fptr;
    FILE* ftemp;
    fptr = fopen(v_id, "r");
    fptr2 = fopen("servicestest.txt", "r");
    ftemp = fopen("replacetemp.txt", "w");
    while (fgets(line, BUFFER_SIZE, fptr))
    {
        printf("%s\n", line);
    }

    printf("\nEnter the information accordingly\n");

    rewind(fptr);
    stat = 0;

    while (stat == 0)
    {
        printf("TOS: ");
        scanf("%s", &tos);
        getchar();
        while (fgets(line, BUFFER_SIZE, fptr) != 0)
        {
            if (strstr(line, tos))
            {
                stat = 1;
            }
        }
    }

    rewind(fptr);
    stat = 0;

    while (stat == 0)
    {
        printf("Customer Status: ");
        scanf("%s", &cust_stat);
        getchar();
        while (fgets(line, BUFFER_SIZE, fptr) != 0)
        {
            printf("it did enter here");
            if (strstr(line, cust_stat))
            {
                stat = 1;
            }
        }
    }

    rewind(fptr);
    stat = 0;

    while (stat == 0)
    {
        printf("Needed days: ");
        scanf("%s", &n_daysasd);
        while (fgets(line, BUFFER_SIZE, fptr))
        {
            if (strstr(line, n_daysasd))
            {
                stat = 1;
            }
        }
    }

    rewind(fptr);
    stat = 0;

    while (stat == 0)
    {
        printf("Total Fee: ");
        scanf("%s", &tot_fee);
        while (fgets(line, BUFFER_SIZE, fptr))
        {
            if (strstr(line, tot_fee))
            {
                stat = 1;
            }
        }
    }

    while (fgets(line, BUFFER_SIZE, fptr2))
    {
        if (strstr(line, v_id))
        {
            fprintf(ftemp, "Visit ID: %s, Customer ID : %s, TOS : %s, Customer Status : %s, Needed Days : %s, Total Fee : %s, Payment : Not Made", v_id, c_id, tos, cust_stat, n_daysasd, tot_fee);
        }
        else
        {
            fputs(line, ftemp);
        }
    }

    fclose(fptr);
    fclose(fptr2);
    fclose(ftemp);

    remove("servicestest.txt");

    rename("replacetemp.txt", "servicestest.txt");

The summary is that here

while (stat == 0)
        {
            printf("TOS: ");
            scanf("%s", &tos);
            getchar();
            while (fgets(line, BUFFER_SIZE, fptr) != 0)
            {
                if (strstr(line, tos))
                {
                    stat = 1;
                }
            }
        }

This is the sample input

enter image description here

I tried to input randomly but then input properly what it was supposed to do, but for some reason, it displays TOS: TOS: TOS: TOS: four times which I didn't know why.

and also here is another sample input

enter image description here

it supposed to ask for input but it didn't and it instead skipped to total fee: asking for input, even needed days got skipped.

I did rewind the fptr, so where's the mistake? why it's not waiting for input?

Lorale
  • 113
  • 6

0 Answers0