###前提・実現したいこと
構造体でポインタの配列を使って文字列を読み込むプログラムなのですが、ポインタ配列をEOFで判定できないとエラーが出てわからなくなりました。
どこが間違っているのか教えてほしいです><
###発生している問題・エラーメッセージ
pref3main.c: In function ‘main’:
pref3main.c:12:14: error: ‘EOF’ undeclared (first use in this function)
pref3main.c:12:14: note: each undeclared identifier is reported only once for each function it appears in
エラーメッセージ
###該当のソースコード
#define N 3 #define LINELEN 128 #define data 47 typedef struct { char name[NAMELEN+1]; /* 県名 */ double area; /* 面積 (km2)*/ int population; /* 人口 (人) */ } pref_t; pref_t *pref_new(char *name, double area, int population) ; void pref_print(pref_t* p) ; pref_t *pref_new_scan(); #include <stdlib.h> #include <stdio.h> #include <string.h> #include "pref.h" int main(void) { pref_t *p[data]; int i; int count=0; for(i=0;;i++){ p[i]=pref_new_scan(); if(p[i]==EOF){break;} count++; } for(i=count;i>0;i--){ pref_print(p[i]); } for(i=0;i<count;i++){ free(p[i]); p[i]=NULL; } return 0; } #include <stdio.h> #include <stdlib.h> #include <string.h> #include "pref.h" #define NAMELEN 15 pref_t *pref_new(char *name, double area, int population){ pref_t *x; //動的割り当て x = (pref_t *) malloc(sizeof(pref_t)); /* 値の代入 */ strncpy(x->name, name, NAMELEN); x->area = area; x->population = population; return x; } void pref_print(pref_t* p){ printf("%-10s %9.2f %9d\n", p->name, p->area, p->population); } pref_t *pref_new_scan(){ pref_t *p; char s[LINELEN+1]; //動的割り当て p=(pref_t*)malloc(sizeof(pref_t)); if(scanf("%s",p->name)==EOF){return NULL;} if(scanf("%lf",p->area)==EOF){return NULL;} if(scanf("%d",p->population)==EOF){return NULL;} return p; } ここにご自身が実行したソースコードを書いてください
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。