我是新来的,很抱歉有任何误会。我正在学习C语言上的随机存取文件。我对变量blankClient感到困惑。它不是一个数组,但Deitel (作者)如何使用空白客户端初始化100个空白记录。我认为它应该是这样的:结构客户端数据blankClient100;
/*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;
}发布于 2014-05-27 04:54:43
代码写出相同的源记录100次。这类似于你如何只用两只手就能发出一百个鼓掌的声音。
https://stackoverflow.com/questions/23877584
复制相似问题