2006年9月全國(guó)等級(jí)考試三級(jí)c語(yǔ)言上機(jī)題庫(kù)(十一)
☆題目11(無(wú)憂id 93 字符串字母移位題) 程序prog1.c的功能是:把 s 字符串中的所有字母改寫成該字母的下一個(gè)字母,字母z改寫成字母a。要求大寫字母仍為大寫字母,小寫字母仍為小寫字母,其它字符不做改變。請(qǐng)考生編寫函數(shù)chg(char *s)實(shí)現(xiàn)程序要求,最后調(diào)用函數(shù)readwritedat( )把結(jié)果輸出到文件bc1.out中。例如:s 字符串中原有的內(nèi)容為:mn.123zxy,則調(diào)用該函數(shù)后,結(jié)果為:no.123ayz。注意:部分源程序存在文件prog1.c文件中。請(qǐng)勿改動(dòng)主函數(shù)main( )和輸出數(shù)據(jù)函數(shù)readwritedat()的內(nèi)容。#include <conio.h>#include <string.h>#include <stdio.h>#include <ctype.h>#define n 81void 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) ;}