2017-05-29 14 views
0

次のコードはファイル処理用のコードです。私にとって混乱しているのは、feof()はどのように機能するのですか?また、fprintf()fscanf()の作業を私に説明してください。Cのfeof()について混乱しています

#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; 
} 
+0

宣言と代入を分離しなきゃ](https://linux.die.net/man/3/feof)、['fprintf'](https://linux.die.net/man/3/fprintf)、[' fscanf'](https: //linux.die.net/man/3/fscanf)。 – cubrr

+0

また、ここに投稿する際にコードを正しくインデントしてください。 –

答えて

-2

あなたが受け取っているエラーは何ですか?

cfptrの=ののfopen( "clients.dat"、 "W") あなたはhere.Youを割り当てることはできません。まず、[ `feof`のマンページを見てみましょう

+0

まず、Cで宣言と代入を「分離する」必要はありません。これを_initialization_と呼びます。第2に、 'cfptr'が既に前の行で宣言されているので、ここでは宣言はありません。 –

関連する問題