我是新来的,如有任何误解,我深表歉意。我正在学习 C 语言的随机访问文件。我对变量 blankClient 感到困惑。它不是一个数组,但Deitel(作者)如何使用空白客户端初始化100个空白记录。我虽然应该是这样的: struct clientdata blankClient[100];
/*Creating a random-access file sequentially */
#include <stdio.h>
struct clientdata {
int acctNum; /*account number*/
char lastname[15]; /*account last name*/
char firstname[10]; /*account first name */
double balance; /*account balance*/
};
int main (void){
int i; /*counter used to count from 1-100 */
/*create clientData with default info */
struct clientdata blankClient = {0, "","", 0.0};
FILE *cfPtr; /*credit.dat file pointer */
if ((cfPtr =fopen("credit.dat", "wb")) == NULL) {
printf("File could not be opened. \n");
}
/*output 100 blank records to file */
else {
for (i=1; i<=100; i++) {
fwrite(&blankClient, sizeof( struct clientdata), 1, cfPtr);
}
fclose (cfPtr);
}
return 0;
}