-1
// Creating a sequential file

#include <stdio.h>

int main() {

    FILE* cfPtr; // pointer to FILE structure
    
    cfPtr = fopen("clients.txt","r");
    if (cfPtr == NULL) {
        puts("File could not be opened.");
    }
    
    else {
        unsigned int account;
        char name [30];
        double balance;
        
    printf("%-10s%-13s%s\n","Account","Name","Balance");
    fscanf(cfPtr,"%d%29s%lf",&account,name,&balance);
    
    while (!feof(cfPtr)) {
        printf("%-10s%-13s%7.2f\n",account,name,balance);
        fscanf(cfPtr,"%d%29s%lf",&account,name,&balance);
    }
    fclose(cfPtr);
}

I can write records to the file but i can not read and print the records in this file to the console.

πάντα ῥεῖ
  • 85,314
  • 13
  • 111
  • 183
  • 2
    Maybe this is worth a read [Why is `while ( !feof (file) )` always wrong?](https://stackoverflow.com/q/5431941/2436655) – pzaenger Jun 04 '22 at 09:17
  • What do you mean by "i can not read and print the records in this file to the console"? What happens instead? – Yunnosch Jun 04 '22 at 09:35
  • 1
    Maybe because the posted code is missing the closing `}` for `main` ? You got anything else besides this-don't-work? What have you done so far to *debug* this? – WhozCraig Jun 04 '22 at 09:38
  • 1
    You must check the value returned by `scanf()`; it can fail without reaching EOF. You should show some of the content of the data file, or how it is written. – Jonathan Leffler Jun 04 '22 at 10:39

0 Answers0