2006年全国房价_2006年9月全国等级考试三级c语言上机题库(十一)

试题集锦 2023-06-16 网络整理 可可

【shitiku.jxxyjl.com--试题集锦】

☆题目11(无忧id 93 字符串字母移位题)

 

程序prog1.c的功能是:把 s 字符串中的所有字母改写成该字母的下一个字母,字母z改写成字母a。要求大写字母仍为大写字母,小写字母仍为小写字母,其它字符不做改变。

请考生编写函数chg(char *s)实现程序要求,最后调用函数readwritedat( )把结果输出到文件bc1.out中。

例如:s 字符串中原有的内容为:mn.123zxy,则调用该函数后,结果为:no.123ayz。

注意:部分源程序存在文件prog1.c文件中。

请勿改动主函数main( )和输出数据函数readwritedat()的内容。

#include <conio.h>

#include <string.h>

#include <stdio.h>

#include <ctype.h>

#define n 81

void readwritedat();

 

void chg(char *s)

{while(*s)

if(*s=="z"||*s=="z") {*s-=25; s++;}

else if(*s>="a"&&*s<="y") {*s+=1;s++;}

else if(*s>="a"&&*s<="y") {*s+=1;s++;}

else s++;

}

 

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\n", a) ;

}

fclose(rf) ;

fclose(wf) ;

}

本文来源:https://shitiku.jxxyjl.com/shitijijin2/27237.html

Copyright @ 2011- 考试题库网 All Rights Reserved. 版权所有

免责声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。

 站长统计