功能是:把 s 字符串中的所有字母改写成该字母的下一个字母,字母 z 改写 成字母 a。要求大写字母仍为大写字母,小写字母仍为小写字母,其它字符不做改变。
请编写函数 chg(char *s)实现程序要求,后调用函数 readwriteDAT( )把结果输 出到文件 bc1.out 中。
例如:s 字符串中原有的内容为:Mn.123Zxy,则调用该函数后,结果为:No.123Ayz。
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#define N 81 void readwriteDAT();
void chg(char *s)
{int I;
for(I=0;I<strlen(s);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\n”, a) ;
}
fclose(rf) ;
fclose(wf) ;
}