注意:源程序存放在考生文件夹下的BLANK1.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);
}
解题答案:
/**********第一空**********/
int fun(STYPE *std)
/**********第二空**********/
FILE *fp; int i;
/**********第三空**********/
fwrite(&std[i], sizeof(STYPE), 1, fp);
****************************************** [NextPage] 二、改错题:给定程序MODI1.C中函数fun的功能是:先将在字符串s中的字符按正序存放到t串中,然后把s中的字符按逆序连接到t串的后面。
例如:当s中的字符串为:"ABCDE"时,
则t中的字符串应为:"ABCDEEDCBA"。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#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);
}
解题答案:
/************found************/
for(i=0; i<= sl; i++)
/************found************/
t[2*sl]='\0';
******************************************
[NextPage] 三、程序题:函数fun的功能是:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的千位和十位上, b数的十位和个位数依次放在c数的百位和个位上。例如,当a=45,b=12时,调用该函数后,c=4152。
注意: 部分源程序存在文件PROG1.C中。数据文件IN.DAT中的数据不得修改。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#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 ()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *rf, *wf ;
int i, a,b ; long c ;
rf = fopen("in.dat", "r");
wf = fopen("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);
}
解题答案:
{
*c=(a/10)*1000+(b/10)*100+(a%10)*10+(b%10);
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|