2014年3月全国计算机二级C语言上机模拟试题八十五

2014-11-02 17:00:07 · 作者: · 浏览: 84

  请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。


  注意:源程序存放在考生文件夹下的BLANK1.C中。


  不得增行或删行,也不得更改程序的结构!


  给定源程序:


  #include


  #include


  #define N 5


  typedef struct


  { int num;


  char name[10];


  char tel[10];


  }STYPE;


  void check();


  int fun(___1___ *std)


  {


  ___2___ *fp; int i;


  if((fp=fopen("myfile5.dat","wb"))==NULL)


  return(0);


  printf("\nOutput data to file !\n");


  for(i=0; i   fwrite(&std[i], sizeof(STYPE), 1, ___3___);


  fclose(fp);


  return (1);


  }


  main()


  { STYPE s[10]={ {1,"aaaaa","111111"},{1,"bbbbb","222222"},{1,"ccccc","333333"},


  {1,"ddddd","444444"},{1,"eeeee","555555"}};


  int k;


  k=fun(s);


  if (k==1)


  { printf("Succeed!"); check(); }


  else


  printf("Fail!");


  }


  void check()


  { FILE *fp; int i;


  STYPE s[10];


  if((fp=fopen("myfile5.dat","rb"))==NULL)


  { printf("Fail !!\n"); exit(0); }


  printf("\nRead file and output to screen :\n");


  printf("\n num name tel\n");


  for(i=0; i   { fread(&s[i],sizeof(STYPE),1, fp);


  printf("m %s %s\n",s[i].num,s[i].name,s[i].tel);


  }


  fclose(fp);


  }


  233网校编辑推荐