① c语言编程,编写函数,删除字符串中的英文字母、数字字符;并对连续出现的相同字符,将其缩减为一个。
#include<stdio.h>
voidfun(char*s){
inti,j;
for(i=0;s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z'||s[i]>='0'&&s[i]<='9';i++);
for(s[j=0]=s[i++];s[i];i++)
if(!(s[i]>='a'&&s[i]<='z'||s[i]>='A'&&s[i]<='Z'||s[i]>='0'&&s[i]<='9')&&s[i]-s[j])
s[++j]=s[i];
s[j+1]='';
}
intmain(intargc,char*argv[]){
chars[81];
printf("Inputastring... s=");
fgets(s,81,stdin);
fun(s);
printf("%s",s);
return0;
}
② c语言中如何删除字符串中的字母
用下面的for 循环语句:从最后一个字符查起,若是字母,则做 strcpy(s+i,s+i+1);
程序如下。
#include <stdio.h>
int main(){
char s[100];
int i,L;
printf("input a string:\n");
gets(s);
printf("orig: %s\n",s);
L=strlen(s);
// printf("L: %d\n",L);
for (i=L-1;i>=0;i--)
if ((s[i] >= 'a' && s[i] <= 'z')||(s[i]>='A' && s[i]<='Z'))
strcpy(s+i,s+i+1);
printf("result: %s\n",s);
return 0;
}
③ 急!C语言编程,删除从键盘输入的字符串中的小写字母,结果仍放在原串中。
1、新建工程和文件,然后开始写好我们的程序模板。
④ c语言中删除字符串中字母的方法
可以根据字符的ASCII码值来判断字符是否是字母,之后将非字母字符存放到另一个字符串数组中,即可达到删除字符串中字母的目的。
具体实现方法可以参考如下程序:
#include<stdio.h>
#include<ctype.h>//isalpha函数的头文件
voidmain()
{
char*str1=(char*)malloc(50*sizeof(char));//定义字符指针str1,并申请内存空间,存放用户输入的字符串,最大50个字符
char*str2;//存放去掉字母后的字符串
inti=0;
scanf("%s",str1);//接收用户输入的字符串
str2=(char*)malloc(sizeof(str1));
while(*str1!='')
{
if(!isalpha(*str1))//如果不是字母字符,则存放于str2字符串中
{
*(str2+i)=*str1;
i++;
}
str1++;
}
*(str2+i)='';//将str2末尾字符置结束字符标志
printf("%s ",str2);//输出去掉字母后的字符串
}
⑤ 删除字符串中的小写字母
#include<stdio.h>
#include<string.h>
char* new(char*_new,char*_old)//new函数:new是关键字 不能当变量雀轿大
{
int i,q;
for(i=q=0;NULL!=_old[i];i++)
if(_old[i]>='a'&&_old[i]<='z')
continue;
else _new[q++]=_old[i];
_new[q]='\0';
return _new;
}
int main()
{
char *_old="heLLOWorld!";//初始化字符帆孝串
char *_new=new char[strlen(_old)];//动态申请内存
new(_new,_old);//调用new函数
printf("%s\n",_new);//输出去掉小写字母后的字符串顷竖
return 0;
}
⑥ c 语言删除小写字母
include<stdio.h>
voidmain()
{
inti,j;
chara[80];
for(i=0;i<80;i++)
{
scanf("%c",&a[i]);
if(a[i]==' ')break;
}
a[i]='';
for(i=0;a[i]!='';i++)
if((a[i]>='a')&&(a[i]<='z'))
{友塌枣//加括号
for(j=i;a[j]!='';j++)
a[i]=a[i+1];
i--;//加这句!因为将后面的字母前移后,好拆要重新从该位检衫困查才可以!
}//---
for(i=0;a[i]!='';i++)
printf("%c",a[i]);
printf(" ");
}