C语言上机练习题.docVIP

  • 16
  • 0
  • 约26.94万字
  • 约 287页
  • 2017-01-06 发布于贵州
  • 举报
C语言上机练习题C语言上机练习题

目录 第01套 一:基本操作第一套第一题:STYPE , FILE, fp 第二题: for(i = 0 ; i sl ; i++) , t[2*sl] = 0; 第三题: *c=(a/10)*1000+(b/10)*100+(a%10)*10+(b%10); 给定程序的功能是调用fun函数建立班级通讯录。通讯录中记录每位学生的编号、姓名和电话号码。班级的人数和学生的信息从键盘读入,每个人的信息作为一个数据块写到名为myfile5.dat的二进制文件中。 请在程序下的下划线处填入正确的内容并把下划线删除,使程序得出正确结果。 注意:源程序存放在考生文件夹下的BLANK1.C。 不得增行或删行,也不得更改程序的结构。 #include stdio.h #include stdlib.h #define N 5 typedef struct { int num; char name[10]; char tel[10]; }STYPE; void check(); /**********found**********/ int fun(___1___ *std) { /**********found**********/ ___2___ *fp; int i; if((fp=fopen(myfile5.dat,wb))==NULL) return(0); printf(\nOutput data to file !\n); for(i=0; iN; i++) /**********found**********/ 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; iN; i++) { fread(s[i],sizeof(STYPE),1, fp); printf(%6d %s %s\n,s[i].num,s[i].name,s[i].tel); } fclose(fp); } 二:简单应用 给定程序MOD1.C中函数fun的功能是:先将在字符串S中的字符按正序存放到t串中,然后把S中的字符按逆序连接到t串的后面。 例如:当S?中的字符串为: “ABCDE”时, 当t中的字符串应为: “ABCDEEDCBA” 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 #include stdio.h #include string.h void fun (char *s, char *t) { int i, sl; sl = strlen(s); /************found************/ for( i=0; i=s1; i ++) t[i] = s[i]; for (i=0; isl; i++) t[sl+i] = s[sl-i-1]; /************found************/ t[sl] = ‘\0’; } main() { char s[100], t[100]; printf(\nPlease enter string s:); scanf(%s, s); fun(s, t); printf(The result is: %s\n, t); } 三:

文档评论(0)

1亿VIP精品文档

相关文档