fig23_11.c

来自「经典vc教程的例子程序」· C语言 代码 · 共 31 行

C
31
字号
/* Creating a randomly accessed file sequentially */
#include <stdio.h>

struct clientData {
   int acctNum;
   char lastName[15];
   char firstName[10];
   float balance;
};

main()
{
   int i;
   struct clientData blankClient = {0, "", "", 0.0};
   FILE *cfPtr;

   if ((cfPtr = fopen("credit.dat", "w")) == NULL)
      printf("File could not be opened.\n");
   else {

      for (i = 1; i <= 100; i++)
         fwrite(&blankClient, 
                sizeof(struct clientData), 1, cfPtr);

      fclose (cfPtr);
   }

   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?