急求!C语言编写一函数,把一个字符串中所有的字母或数字字符都去掉,产生一个新字符串,main函数输入输出

如题所述

#include <stdio.h>
void Deld(char *str)
{
char tmp[100];
int i,j=0;
for (i=0;str[i];i++)
if (str[i]>= 'a'&&str[i]<='z'||str[i]>='A'&&str[i]<='Z') //删除字母,若是数字,改为<='9'&&>='0'
tmp[j++] = str[i];
tmp[j] = '\0';
for (i=0;tmp[i];i++)
str[i] = tmp[i];
str[i] = '\0';
}

void main()
{
char str[111] = "hello world!";
Deld(str);
printf("%s",stsr);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-05-30
#include <stdio.h>
#include <ctype.h>

char* fun(char* s)
{
char* p = s;
char* q = s;
while(*p)
{
if( !(isdigit(*p) || isalpha(*p)) )
{
*q = *p;
q++;
}
p++;
}
*q = 0;
return s;
}

int main()
{
char input[1000];
while(scanf("%s",input)==1)
{
printf("%s\n",fun(input));
}
}本回答被提问者采纳