c语言指针输入一个字符串,将这个字符串中的大写英文字母除去,输出剩余的字符组成的字符串。(要求用指针做)
时间: 2023-06-05 17:09:10 浏览: 83
可以使用指针遍历字符串中的每一个字符,判断是否为大写字母,如果不是则加入到新的字符数组中,最后输出新的字符数组即可。
以下是示例代码:
```c
#include <stdio.h>
#include <ctype.h> // 包含判断字符类型的函数
int main() {
char str[100];
printf("请输入一个字符串:");
scanf("%s", str);
// 新建字符数组
char new_str[100];
char *p = str;
int j = 0;
// 遍历字符串中的每一个字符
while (*p != '\0') {
if (!isupper(*p)) { // 判断是否为大写字母
new_str[j] = *p;
j++;
}
p++;
}
new_str[j] = '\0'; // 字符数组的末尾要加上终止符 '\0'
// 输出新的字符串
printf("去除大写字母后的字符串为:%s\n", new_str);
return 0;
}
```
相关问题
用c语言实现输入一个字符串,将这个字符串中的大写英文字母除去,输出剩余的字符组成的字符串。(要求用指针做)
好的,这个问题属于编程问题,我可以回答。以下是用 C 语言实现输入一个字符串,将这个字符串中的大写英文字母除去,输出剩余的字符组成的字符串的代码,使用了指针:
```c
#include <stdio.h>
#include <ctype.h>
void remove_uppercase(char *str) {
while (*str) {
if (isupper(*str)) { // 判断是否为大写字母
char *end = str;
while (*end) { // 删除当前位置的大写字母
*end = *(end + 1);
end++;
}
}
else {
str++; // 不是大写字母的话,指针向后移动一位
}
}
}
int main() {
char str[100];
printf("请输入字符串:");
scanf("%[^\n]", str);
remove_uppercase(str); // 调用函数删除大写字母
printf("结果:%s\n", str);
return 0;
}
```
使用这个程序,你可以输入一个字符串,程序将输出不含大写字母的字符串。注意,代码中使用了 `isupper()` 函数来判断是否为大写字母。
输入一个字符串,将这个字符串中的大写英文字母除去,输出剩余的字符组成的字符串。用c语言的指针写
以下是C语言指针实现的代码:
```
#include <stdio.h>
void removeUpperCase(char *str) {
while (*str) {
if (*str >= 'A' && *str <= 'Z') {
*str = *(str + 1);
} else {
str++;
}
}
}
int main() {
char str[100];
printf("请输入一个字符串:");
scanf("%s", str);
removeUpperCase(str);
printf("去掉大写字母后的结果为:%s\n", str);
return 0;
}
```
注:这个代码可能经过了人工修改以符合平台规范。