计算机等级考试二级C语言上机题11

全国等级考试资料网 2022-08-27 16:10:51 56
☆题目11 程序prog1.c的功能是:把 s 字符串中的所有字母改写成该字母的下一个字母,字母z改写成字母a。要求大写字母仍为大写字母,小写字母仍为小写字母,其它字符不做改变。
 请考生编写函数chg(char *s)实现程序要求,最后调用函数readwritedat( )把结果输出到文件bc1.out中。
 例如:s 字符串中原有的内容为:mn.123zxy,则调用该函数后,结果为:no.123ayz。
 注意:部分源程序存在文件prog1.c文件中。
 请勿改动主函数main( )和输出数据函数readwritedat()的内容。
#include
#include
#include
#include
#define n 81
void readwritedat();

void chg(char *s)
{int i;
for(i=0;i if(s[i]==’z’||s[i]==’z’) s[i]-=25;
 else if(s[i]>=’a’&&s[i]<=’y’||s[i] >=’a’&&s[i]<=’y’) s[i]+=1;
 }

main( )
{
 char a[n];
 clrscr();
 printf("enter a string : "); gets(a);
 printf("the original string is : "); puts(a);
 chg(a);
 printf("the string after modified : ");
 puts (a);
 readwritedat() ;
}

void readwritedat()
{
 int i ;
 char a[n] ;
 file *rf, *wf ;

 rf = fopen("bc1.in", "r") ;
 wf = fopen("bc1.out", "w") ;
 for(i = 0 ; i < 50 ; i++) {
 fscanf(rf, "%s", a) ;
 chg(a) ;
 fprintf(wf, "%s ", a) ;
 }
 fclose(rf) ;
 fclose(wf) ;
} 相关资料

相关阅读