title: C only reads first struct, cannot read other inputs
body: <p>I'm creating a basic grocery delivery system. The code is working properly if you input for the first time. However, if you input another ID, in the receipt part, it just prints "no delivery pending" despite putting the required information.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  struct grocery {
      int number;
      char prod1[20];//products
      char prod2[20];
      char prod3[20];
      char prod4[20];
      float price1; //price of product
      float price2; 
      float price3; 
      float price4; 
      char status; //status of products
      float ttl; //total
  };
  struct grocery g;
  FILE * fptr;
  char prod[][20] = {"tissue","soap","shampoo","lotion","tampons"};
  float price[5] = {1.00, 2.30, 1.50, 4.30, 5.00};
  int orders(int id, int g1, int g2, int g3, int g4) {
      int a;
      fptr = fopen("delivery.txt", "a");
      if (fptr == NULL) {
          fptr = fopen("delivery.txt", "w");
      }
      fflush(stdin);
      g.number = id;
      fflush(stdin);
      //copies file 
      strcpy(g.prod1, prod[g1 - 1]);
      strcpy(g.prod2, prod[g2 - 1]);
      strcpy(g.prod3, prod[g3 - 1]);
      strcpy(g.prod4, prod[g4 - 1]);
      g.price1 = price[g1 - 1];
      g.price2 = price[g2 - 1];
      g.price3 = price[g3 - 1];
      g.price4 = price[g4 - 1];
      g.status = 'd'; //status is set to 'being delivered(d)'
      fseek(fptr, 0, SEEK_END);
      fwrite(&amp;g, sizeof(struct grocery), 1, fptr);
      fflush(stdin);
      printf("\n\n\n\tyour items are being delivered\n\n\n");
      fflush(stdin);
      fclose(fptr);
      return 1;
  }
  void receipt(int id) {
      float total, mon, change; //mon -&gt; money given by user
      int c = 0;
      fptr = fopen("delivery.txt", "r+");
      if (fptr == NULL) {
          printf("error opening file\n\n");
          exit(0);
      }
      while (fread(&amp;g, sizeof(struct grocery), 1, fptr) == 1) {
          if (g.number == id) {
              printf("\tdelivery total: \n");
              printf("\t%s\t%20.2f\n", g.prod1, g.price1);
              printf("\t%s\t%20.2f\n", g.prod2, g.price2);
              printf("\t%s\t%20.2f\n", g.prod3, g.price3);
              printf("\t%s\t%20.2f\n", g.prod4, g.price4);
              total = g.price1 + g.price2 + g.price3;
              g.ttl = total;
              printf("\t-----------------------------\n");
              printf("\ttotal                   $%.2f\n", total);
              do {
                  printf("\tcash :               $");
                  scanf("%f", &amp;mon);
                  if (mon &lt; total) {
                      c = 0;
                      printf("\n\t insufficient amount...try again\n\n");
                  }
                  else {
                      g.status = 'r'; //changes status to "received"
                      c = 1;
                      change = mon - total;
                      printf("\tchange:       $%.2f\n", change);
                  }
  
          } while (c == 0); 
          }
          else {
              printf("no delivery pending. \n\n");
              exit(0);
          }
      }
  }
  
  int main(){
      int id, a, b, c, d; //a,b,c,d are the items the user wants to buy
      int e = 0; 
      printf("enter USER ID to continue... ");
      scanf("%d", &amp;id);
      printf("ITEMS LIST: \n");
      printf("1 - tissue\n 2 - soap \n 3 - shampoo \n 4 - lotion \n 5 - tampons \n");
      printf("enter item codes: ");
      scanf("%d%d%d%d", &amp;a, &amp;b, &amp;c, &amp;d);
      e = orders(id, a, b, c, d);
      if (e == 1)
          receipt(id);
  }
  </code></pre>
  
  <p>I can type any ID and it prints the receipt just fine but I try another one it just goes to the else statement.</p>