常规做法用字符串数组遍历输出字符即可。 需要注意的是题干中说要输入一端全为小写的字符串,由于scanf好像没有小写的输入格式所以这里先读取一端字符串,再对字符串进行处理。 这里用来一个islower函数,其可以判断字符是否为小写字母。这里判断若字符为小写字符则将它赋值给str字符串中。 #include<stdio.h> #include<string.h> #include<ctype.h> int main() { char in[1000]={0}; char str_low[1000]={0}; scanf("%s",in); int i=0; //保证字符串为小写 while(in[i]!='\0') { if(islower(in[i])) str_low[i]=in[i]; i++; } for(i=strlen(str_low)-1;i>=0;i--) { printf("%c",str_low[i]); } return 0; }
时间: 2023-05-22 17:01:25 浏览: 50
这道题的常规做法是使用字符串数组遍历输出字符。需要注意的是,题目要求输入的字符串全为小写字母,但是scanf函数好像没有专门的小写输入格式。因此,我们先读取一段字符串,然后再对字符串进行处理。
在处理字符串时,我们可以使用一个islower函数,它可以判断一个字符是否为小写字母。如果字符是小写字母,我们就将它赋值给一个新的字符串str中。
最终,我们遍历输出字符串str即可。
相关问题
c语言输入字符串数组并遍历数组
下面是一个示例代码,可以用来输入字符串数组并遍历数组:
```c
#include <stdio.h>
#include <string.h>
#define MAX_SIZE 5 // 字符串数组的最大长度
int main() {
char str_array[MAX_SIZE][100]; // 定义一个字符串数组
int i;
printf("请输入 %d 个字符串:\n", MAX_SIZE);
// 循环输入字符串
for (i = 0; i < MAX_SIZE; i++) {
scanf("%s", str_array[i]);
}
// 输出字符串
printf("输入的字符串为:\n");
for (i = 0; i < MAX_SIZE; i++) {
printf("%s\n", str_array[i]);
}
return 0;
}
```
在这个示例代码中,我们定义了一个字符串数组 `str_array`,它的长度为 `MAX_SIZE`,每个字符串的最大长度为 100。然后,我们使用循环来输入字符串,最后再循环输出字符串。你可以根据自己的需要修改 `MAX_SIZE` 的值。
scanf输入字符串数组
scanf函数可以用来输入字符串数组。可以使用%c格式符来逐个输入字符,并将其存储在字符数组中。为了输入完整的字符串,可以使用循环来连续输入字符,直到遇到结束标志。例如,可以使用do-while循环来输入字符串,并使用字符#作为结束标志。下面是一个示例代码:
```c
#include <stdio.h>
int main(void) {
char array\[50\];
int i = 0;
do {
scanf("%c", &array\[i\]);
} while (array\[i\] != '#' && ++i);
array\[i\] = '\0';
printf("The string is: %s\n", array);
return 0;
}
```
在这个示例中,我们使用了do-while循环来连续输入字符,并将其存储在字符数组中,直到遇到字符#为止。然后,我们在数组的末尾添加了一个空字符,以表示字符串的结束。最后,我们使用printf函数将输入的字符串输出到屏幕上。
#### 引用[.reference_title]
- *1* [总结:C语言字符串输入的三种方式(scanf("%c",array); scanf("%s",str); gets(array);)](https://blog.csdn.net/qq_41631679/article/details/84239985)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* *3* [C语言字符数组的输入与输出:scanf,printf,getchar,putchar,gets使用方法](https://blog.csdn.net/qq_41706331/article/details/86406448)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)