1、输入一个字符串和一个正整数x,将该字符串中的后x个字符复制到另一个字符串y中,输出字符串y;再对y串的内容前后倒置后存入数组z中并输出。
要求:用指针访问数组元素、用函数getx(char *c1)实现复制、用函数getr(char *c2)实现倒置。
运行示例
Enter a string: abcABCD
Enter an integer: 4
The new string is: ABCD
The invert string is: DCBA
----------------------------------分割线----------------------------------
2、为了防止信息被别人轻易窃取,需要把电码明文通过加密方式变换成为密文。变换规则是:小写字母z变换成为a,其它字符变换成为该字符ASCII码顺序后1位的字符,比如o变换为p。
要求输入一个字符串(少于80个字符),输出相应的密文;要求定义和调用函数encrypt(s),该函数将字符串s变换为密文。
#include<stdio.h> #include<string.h> /*定义字符串*/ #define MAXLINE 80 /*不超过80个字符*/ void encrypt (char *); int main(void) { char line [MAXLINE]; /*字符数组line用于存放输入的字符串*/ printf("Input the srting:"); gets(line); encrypt(line); /*调用加密指针encrypt*/ printf("%s%s ","After being encrypted:",line); return 0; } void encrypt(char *s) { for(;*s!='