lundi 29 juin 2015

File processing in C; won't take input

I'm starting to learn file processing in C. The point of this specific program is to make a file called "clients.dat" where I store the account number, name, and balance of clients at a bank, lets say. I've worked and refined the code so that its a perfect replica of what the textbook provides as an example, yet for some reason mine loops endlessly after the first "scanf" and reprints question marks unto oblivion, without ever making it to the scanf statement inside the while loop. Would anyone have any suggestions as to why this is happening? My compiler is Netbeans and I'm running it on Linux-Ubuntu.

#include <stdio.h>
#include <stdlib.h>

int main() {

    unsigned int actNumber;
    char actName[30];
    long double actBalance;

    FILE *fPtr;

    if((fPtr = fopen("clients.dat", "w")) == NULL) {
        printf("File could not be found.\n");

    else {
        printf("Enter the Account Number, Name, and Balance.\n Hit the EoF to exit.\n");
        scanf("%d%29s%lf", &actNumber, actName, &actBalance);

        while (!feof(stdin)) {            
            fprintf(fPtr, "%d, %29s, %.2lf\n", actNumber, actName, actBalance);
            printf("%s", "?");
            scanf("%d%29s%lf", &actNumber, actName, &actBalance);                        


Aucun commentaire:

Enregistrer un commentaire