本文共 1690 字,大约阅读时间需要 5 分钟。
[电脑基础知识]C语言上机题库及解析
第一套
一、填空
#include
#include
#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
/**********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; i
{ fread(&s[i],sizeof(STYPE),1, fp);
printf("%6d %s %s\n",s[i].num,s[i].name,s[i].tel);
}
fclose(fp);
}
答案:1.STYPE
2.FILE
3.fp
二、改错
#include
#include
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
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);
}
答案:1.for(i=0;i
2.t[2*s1]=0
三、编程
#include
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 ( )
{/* ±?oˉêyó?óú′ò?a???t£?ê?è?êy?Y£?μ÷ó?oˉêy£?ê?3?êy?Y£?1?±????t?£ */
FILE *rf, *wf ;
int i, a,b ; long c ;
rf = f
转载地址:http://dhvqa.baihongyu.com/