第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; i<N; 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"}};
fopen和open区别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<N; 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; i<=s1; i ++)
t[i] = s[i];
for (i=0; i<sl; 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);
}
三、程序编写题
#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\\24010001\\in.dat", "r") ;
wf = fopen("K:\\k01\\24010001\\out.dat","w") ;
for(i = 0 ; i < 10 ; i++) {
fscanf(rf, "%d,%d", &a, &b) ;
fun(a, b, &c) ;
fprintf(wf, "a=%d,b=%d,c=%ld\n", a, b, c) ;
}
fclose(rf) ;
fclose(wf) ;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论