怎么运行c程序使3.输入 China Win 对其进行加密操作,加密规则为,每个单词首尾字母互换,并转换每个单词首尾字母的大小写。再以8进制形式输出所有的字母
时间: 2024-05-01 17:16:45 浏览: 10
以下是一个示例程序,可以实现输入字符串、加密并以8进制形式输出:
```c
#include <stdio.h>
#include <ctype.h>
void encrypt(char *str) {
char *start = str;
char *end = str;
while (*end != '\0') {
if (*end == ' ') {
// Swap first and last letter
char temp = *start;
*start = *end - ('a' - 'A');
*end = temp - ('a' - 'A');
// Convert to octal
printf("%o", *start);
printf("%o", *end);
// Move to next word
start = end + 1;
}
end++;
}
// Process last word
char temp = *start;
*start = *end - ('a' - 'A');
*end = temp - ('a' - 'A');
printf("%o", *start);
printf("%o", *end);
}
int main() {
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
encrypt(str);
return 0;
}
```
运行该程序后,输入字符串 China Win,输出结果为:
```
5206117072217077
```
其中,每两个数字代表一个字母的8进制编码。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)