0

The following code is for file processing. What's confusing to me is how does feof() work? Also please explain to me the working of fprintf(), fscanf().

#include<stdio.h>

int main() {

     int account;
     char name[30];
     double balance;`

     FILE *cfptr;

     if((cfptr=fopen("clients.dat","w"))==NULL) {
           printf("File does not exist.\n");
     }
     else {
         printf("Enter the account, name, balance.\n");
         printf("Enter EOF to end input.\n");
         printf("?");
         scanf("%d%s%1f",&account,name,&balance);

         while(!feof(stdin)) {
             fprintf(cfptr,"%d %s %.2f\n",account, name, balance);
             printf("?");
             scanf("%d%s%1f",&account,name,&balance);
         }

         fclose(cfptr);
    }

    return 0;
}
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • First take a look at the manpages for [`feof`](https://linux.die.net/man/3/feof), [`fprintf`](https://linux.die.net/man/3/fprintf) and [`fscanf`](https://linux.die.net/man/3/fscanf). – cbr May 29 '17 at 15:45
  • Then also please indent your code properly when posting here. – Jens Gustedt May 29 '17 at 15:49

0 Answers0