C语言中有没有去除字符串中标点符号的库函数?

Python015

C语言中有没有去除字符串中标点符号的库函数?,第1张

没有你说的库函数,你可以自定义函数,采用字符函数strchr找到标点符号所在的位置,再用strcpy函数将标点符号之后的字符串拷贝至标点符处覆盖,直至所有的标点符号处理完毕,就可以实现你要的功能。

#include <stdio.h>

char *fun(char *a)

{ char *b=",.:"/* 举例部分标点符号,请自行补充 */

char *temp,ch

int i

for(i=0i<strlen(b)i++){

ch=*(b+i)

temp = (char *)strchr(a,ch)

while( strlen(temp)>0){

if(strlen(temp)>0)

strcpy(temp,temp+1)

temp = (char *)strchr(a,ch)

}

}

return(a)

}

main()

{ char *a="This, is. a,try."

printf("%s\n",a)

printf("%s\n",fun(a))

}

#include<stdio.h>

void main()

{

char a[100]

int i

int j=0

printf("请输入符号:\n")

scanf("%s",a)

for(i=0a[i]!=NULLi++)

{ j++

}

a[0]=' '

a[j-1]=' '

printf("删除后输出:\n%s",a)printf("\n")

}

验证过了。。能执行。。满意请采纳

下面程序

输出大写小写及数字,去掉一切其它字符:

#include

<stdio.h>

main(){

FILE

*fin,

*fout

static

int

c

fin=fopen("abc.txt","r")

fout=fopen("abc2.txt","w")

while(1){

if

(

(c

=

fgetc(fin))==EOF)

break

if

(

(c

>=

'a'

&&

c

<=

'z')

||

(c

>=

'A'

&&

c

<=

'A')

||

(c

>=

'0'

&&

c

<=

'9')

)

fputc(c,fout)

}

fclose(fin)

fclose(fout)

}