c语言中输入一个字符串,将字符串中大写字母删除后,输出该新字符串。

如题所述

代码如下(你自己加上必要的头文件吧):

int main()
{
int indexInp = 0;
int indexRes = 0;
char input[100] = {0};
char result[100] = { 0 };

//输入字符串
scanf("%s", input);

while (input[indexInp] != '\0')//每次读取一个字符,直到字符串结尾
{
//判断字符是否在26个大写字母范围之外,是则保存到result数组中
if (input[indexInp] < 'A' || input[indexInp] > 'Z')
{
result[indexRes] = input[indexInp];
indexRes++;
}
indexInp++;
}

//输出结果
printf("%s", result);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-14
#include <stdio.h>
#include <stdlib.h>
#define N 100
void upCopy(char *,char *);
int main()
{
char *p;
p=malloc(N+1);

char *q;
q=malloc(strlen(p)+1);
printf("请输入一个字符串:");
gets(p);
upCopy(q,p);
printf("%s",q);
system("pause");
}
void upCopy(char *NEW,char *OLD)
{
for(;*OLD;OLD++){
if (*OLD>='A' && *OLD<='Z')
continue;
*NEW++=*OLD;}

*NEW='\0';
}本回答被提问者和网友采纳
第2个回答  2011-12-25
C++写的。。。
#include<iostream>
using namespace std;
long long m;
char a;
string s;
string cut(string p,char q){
while(p.find(q)!=-1){m=p.find(q);p=p.erase(m,1);}
return p;
}
int main(){
cin>>s;
for(a='A';a<='Z';a++)s=cut(s,a);
cout<<s;
system("pause");
return 0;
}
第3个回答  2011-12-18
做一数组 循环 用指针每个都判断 把小写字母填充到空字符串里、、