从键盘输入一个字符串,将其中的大写字母全部转化成小写字母,然后输出到一个磁盘文本文件”test”中保存,输入的字符串以”!”结束。C语言
时间: 2023-07-16 10:14:47 浏览: 46
以下是实现该功能的C语言代码:
```c
#include <stdio.h>
#include <ctype.h>
int main() {
char str[100];
int i = 0;
FILE *fp;
printf("请输入一个字符串(以!结束):\n");
while ((str[i] = getchar()) != '!') {
str[i] = tolower(str[i]);
i++;
}
str[i] = '\0';
fp = fopen("test.txt", "w");
fprintf(fp, "%s", str);
fclose(fp);
printf("转换后的字符串已保存到 test.txt 文件中。\n");
return 0;
}
```
运行时,会提示用户输入一个字符串并以感叹号(!)结束。程序会将输入的字符串中的大写字母全部转化成小写字母,并将结果输出到一个名为 "test.txt" 的文本文件中保存。最后,程序会输出一条提示消息,告诉用户转换后的字符串已保存到文件中。
相关问题
python从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件“test”中保存
好的,您可以尝试以下代码实现:
```python
# 从键盘输入一个字符串
input_str = input("请输入一个字符串:")
# 将小写字母全部转换成大写字母
upper_str = input_str.upper()
# 将转换后的字符串保存到文件中
with open("test", "w") as f:
f.write(upper_str)
print("保存成功!")
```
这段代码的实现过程是:先从键盘输入一个字符串,然后使用字符串的 `upper` 方法将小写字母全部转换成大写字母,最后使用文件操作将转换后的字符串保存到磁盘文件“test”中。
从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到个磁盘文件" test "中保存。
好的,这是一个编程问题。你可以使用各种编程语言来实现这个功能,以下是一种简单的Python代码实现:
```python
string = input("请输入字符串:") # 从键盘输入字符串
string = string.upper() # 将字符串中的小写字母全部转换成大写字母
with open("test.txt", "w") as f: # 打开文件 test.txt
f.write(string) # 将字符串写入文件中
print("已将字符串转换为大写字母并保存到文件 test.txt 中!") # 输出提示信息
```
希望这个答案能够帮到你!
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.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)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-zip](https://img-home.csdnimg.cn/images/20210720083736.png)