title: How can I read from a file having numbers seperated by "\n" in C
body: <p>I am writing a program on <strong><em>Cash Management System</em></strong> and I'm stuck with file handling.
  Its a long program broken into short pieces by using Functions.</p>
  
  <p>The problem is that I am creating a file which will keep the record of reciept cash, I'm suceesfull in storing the data and the file has been created by using these codes &amp; now i want to read the data of the file using <strong>functions</strong> in <strong>C</strong></p>
  
  <pre><code>#include&lt;fstream.h&gt;
  #include&lt;iostream.h&gt;
  #include&lt;graphics.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;stdio.h&gt;
  void main()
  {
   unsigned long long amt=0;
   char ch;
   do
   {
    clrscr();
    int c=0,i=0,gd=DETECT, gm, x=10, y=52, font = 8;
    initgraph(&amp;gd,&amp;gm,"C:\\TC\\BGI");
    settextstyle(font, HORIZ_DIR, 1);
    for (i=0;i&lt;158;i++)
    {
     printf("_");
    }
    outtextxy(x, y, "The amount of Cash Tendered : ");
    gotoxy(48,5);
    scanf("%llu",&amp;amt);
    FILE *fp;
    fp=fopen("TRECIEPT.TXT","a+");
    while((c=getc(fp))!=EOF);
    fprintf(fp,"%llu",amt);
    fprintf(fp,"\n");
    cout&lt;&lt;"\n Do you want to enter more records: ";
    cin&gt;&gt;ch;
   }
   while (ch=='Y' || ch=='y');
   getch();
  }
  </code></pre>
  
  <p><strong>THE MAIN CODE BEING</strong></p>
  
  <pre><code>#include&lt;graphics.h&gt;
  #include&lt;conio.h&gt;
  #include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  
  static int den[9]={1000,500,100,50,20,10,5,2,1};
  
  int ch=0;
  
  void cash_management();
  //void open_cash();
  void transaction();
  void total_reciept();
  void total_payment();
  //void closing_cash();
  //void reciept();
  //void payment();
  //void exchange();
  
  void main()
  {
   clrscr();
   cash_management();
  }
  
  void cash_management()
  {
   clrscr();
   int i=0, gd=DETECT, gm, x=33, y=33, font = 10;
   initgraph(&amp;gd,&amp;gm,"C:\\TC\\BGI");
   settextstyle(font, HORIZ_DIR, 1);
   for (i=0;i&lt;160;i++)
   {
    printf("_");
   }
   outtextxy(x, y, "Welcome To Cash Management System");
   printf("\n\n\n");
   for (i=0;i&lt;160;i++)
   {
    printf("_");
   }
   font=7;
   y=y+100;
   x=70;
   settextstyle(font, HORIZ_DIR, 1);
   outtextxy(x, y, "1). Opening Cash Denomination");
   y=y+30;
   outtextxy(x, y, "2). Transactions");
   y=y+30;
   outtextxy(x, y, "3). Total Recipts");
   y=y+30;
   outtextxy(x, y, "4). Total payments");
   y=y+30;
   outtextxy(x, y, "5). Closing Cash Denomination");
   y=y+30;
   outtextxy(x, y, "6). Exit");
   printf("\n\n\n\n\n\n\n\n\n\n\n\n\n");
   for (i=0;i&lt;160;i++)
   {
    printf("_");
   }
   x=190;
   y=y+74;
   font=6;
   settextstyle(font, HORIZ_DIR, 1);
   outtextxy(x, y, "Enter option to perform =&gt; ");
   gotoxy (52,24);
   do
   {
    scanf("%d",&amp;ch);
   }
   while (ch&lt;1 || ch&gt;6);
   switch (ch)
   {
    case 1:
       {
        printf("case 1"); //open_cash();}
        break;
       }
    case 2:
       {
        transaction();
       }
    case 3:
       {
        total_reciept();
        break;
       }
    case 4:
      {
       total_payment();
       break;
      }
    case 5:
      {
       printf("case 5");//closing_cash();
       break;
      }
    case 6:
      {
       exit(0);
      }
   }
  }
  
  void transaction()
  {
   clrscr();
   int i=0, j=0, gd=DETECT, gm, x=200, y=33, font = 10;
   initgraph(&amp;gd,&amp;gm,"C:\\TC\\BGI");
   settextstyle(font, HORIZ_DIR, 1);
   for (i=0;i&lt;2;i++)
   {
    printf("\t\t\t");
    for (j=0;j&lt;24;j++)
    {
     printf("_");
    }
    printf("\n");
   }
   outtextxy(x, y, "Transactions");
   printf("\n\n\n");
   for (i=0;i&lt;2;i++)
   {
    printf("\t\t\t");
    for (j=0;j&lt;24;j++)
    {
     printf("_");
    }
    printf("\n");
   }
   x=33;
   font=8;
   settextstyle(font, HORIZ_DIR, 1);
   y=y+100;
   outtextxy(x, y, "1). Reciept");
   y=y+30;
   outtextxy(x, y, "2). Payment");
   y=y+30;
   outtextxy(x, y, "3). Exchange");
   y=y+30;
   outtextxy(x, y, "4). Back");
   printf("\n\n\n\n\n\n\n\n\n");
   for (i=0;i&lt;160;i++)
   {
    printf("_");
   }
   y=y+73;
   outtextxy(x, y, "Enter option to perform =&gt;  ");
   gotoxy(42,20);
   do
   {
    scanf("%d",&amp;ch);
   }
   while(ch&lt;1 || ch&gt;6);
   switch (ch)
   {
    case 1:
       {
        printf("case 1");
  //    reciept();
        break;
       }
     case 2:
       {
        printf("case 2");
     //     payment();
        break;
       }
     case 3:
       {
        printf("case 3");
     //     exchange();
        break;
       }
     case 4:
       {
        cash_management();
        break;
       }
    }
  }
  
  void total_reciept()
  {
   unsigned long long amt=0,t_amt=0;
   clrscr();
   int c=0,i=0,gd=DETECT, gm, x=10, y=52, font = 8;
   initgraph(&amp;gd,&amp;gm,"C:\\TC\\BGI");
   settextstyle(font, HORIZ_DIR, 1);
   for (i=0;i&lt;158;i++)
   {
    printf("_");
   }
   outtextxy(x, y, "The Amount of Cash Tendered are : ");
   gotoxy(48,6);
   FILE *fp;
   fp=fopen("TRECIEPT.TXT","a+");
   i=1;
   while((c=getc(fp))!=EOF)
   {
    fscanf(fp,"%llu",&amp;amt);
    printf("\n %d",i);
    printf("   %llu",amt);
    t_amt=t_amt+amt;
    i++;
   }
   printf("\n\n The Total Amount of cash tendered is:  %llu",t_amt);
   getch();
   cash_management();
  }
  
  void total_payment()
  {
   unsigned long long amt=0,t_amt=0;
   clrscr();
   int c=0,i=0,gd=DETECT, gm, x=10, y=52, font = 8;
   initgraph(&amp;gd,&amp;gm,"C:\\TC\\BGI");
   settextstyle(font, HORIZ_DIR, 1);
   for (i=0;i&lt;158;i++)
   {
    printf("_");
   }
   outtextxy(x, y, "The Amount of Cash Paid are : ");
   gotoxy(48,6);
   FILE *fp;
   fp=fopen("TPAYMENT.TXT","a+");
   i=1;
   while((c=getc(fp))!=EOF)
   {
    fscanf(fp,"%llu",&amp;amt);
    printf("\n %d",i);
    printf("   %llu",amt);
    t_amt=t_amt+amt;
    i++;
   }
   printf("\n\n The Total Amount of cash Paid is:  %llu",t_amt);
   getch();
   cash_management();
  }
  </code></pre>