二级C语言题库副本副本.doc

第1套题 一、程序填空题 #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); } 二、程序改错题 #include stdio.h #include string.h void fun (char *s, char *t) { int i, sl; sl = strlen(s); /************found************/ for( i=0; is1; i ++) t[i] = s[i]; for (i=0; isl; i++) t[sl+i] = s[sl-i-1]; /************found************/ t[2*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); } 三、程序编写题 #include stdio.h void fun(int a, int b, long *c) { } main() { int a,b; long c; void NONO ( ); printf(Input a b:); scanf(%d%d, a, b); fun(a, b, c); printf(The result is: %d\n, c); NONO(); } void NONO ( ) {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *rf, *wf ; int i, a,b ; long c ; rf = fopen(K:\\k01\\in.dat, r) ; wf = fopen(K:\\k01\\out.dat,w) ; for(i = 0 ; i 10 ; i++) { fscanf(rf, %d,%d, a, b) ; fun(a, b,

文档评论(0)

1亿VIP精品文档

相关文档