構造体の配列があり、ファイルに保存されます。現在、ファイルには次の 2 行があります。
a a 1
b b 2
ファイルを読み込んで、データを構造体に保存しようとしています:
typedef struct book{
char number[11];//10 numbers
char first[21]; //20 char first/last name
char last[21];
} info;
info info1[500]
into num = 0;
pRead = fopen("phone_book.dat", "r");
if ( pRead == NULL ){
printf("\nFile cannot be opened\n");
}
else{
while ( !feof(pRead) ) {
fscanf(pRead, "%s%s%s", info1[num].first, info1[num].last, info1[num].number);
printf{"%s%s%s",info1[num].first, info1[num].last, info1[num].number); //this prints statement works fine
num++;
}
}
//if I add a print statement after all that I get windows directory and junk code.
これにより、アイテムが構造体に保存されていないと思います。どんな助けでも素晴らしいでしょう。ありがとう!
編集:それで問題なく保存されますが、それを関数に渡すと、ガベージコードが表示されます。
私がそれを呼び出すとき:
sho(num, book);
私のショー機能:
void sho (int nume, info* info2){
printf("\n\n\nfirst after passed= %s\n\n\n", info2[0].first); //i put 0 to see the first entry
}