當前位置:首頁 » 編程語言 » c語言刪標點

c語言刪標點

發布時間: 2024-02-29 17:11:49

c語言中有沒有去除字元串中標點符號的庫函數

沒有你說的庫函數,你可以自定義函數,採用基跡字元函數strchr找到標點符號所在的位置,再用strcpy函數將標點符號之後的字元串拷貝至標點符處覆蓋,直至所有的標點符號處李如理完畢,就可以實現你要的功能。
#include <stdio.h>

char *fun(char *a)
{ char *b=",.;:"; /* 舉例部分標點符號,請自行補充 */哪鋒啟
char *temp,ch;
int i;

for(i=0;i<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));
}

Ⅱ 用c語言編寫程序刪除字元串中間的'*'號

#include<stdio.h>
int main()
{
int i=0, j = 0;
char str1[100], str2[100];
scanf_s("%s", str1,100);
while ( str1[i] != '\0')
{
if (str1[i] != '*')
{
str2[j] = str1[i];
j++;
}
i++;

}
str2[j] = '\0';
printf("%s\n", str2);
return 0;
}
其中scan_s那一列中的 _s 和 ,100 是由於在visual studio 2019上編寫的,其他編譯器可能不一定需要,去掉即可

熱點內容
字元集資料庫 發布:2025-09-08 23:47:35 瀏覽:994
pythonemail解析 發布:2025-09-08 23:37:02 瀏覽:311
android背景高斯模糊 發布:2025-09-08 23:36:03 瀏覽:944
如何解除淘寶的銀行卡快捷支付密碼 發布:2025-09-08 23:35:23 瀏覽:826
手機復制訪問 發布:2025-09-08 23:33:41 瀏覽:226
壓縮a和t 發布:2025-09-08 23:15:12 瀏覽:475
紅米4音樂文件夾是哪個 發布:2025-09-08 23:15:02 瀏覽:35
鐵皮文件櫃密碼盤鎖如何拆解 發布:2025-09-08 23:05:49 瀏覽:988
安卓哪個平板吃雞好 發布:2025-09-08 22:58:53 瀏覽:618
那隻貓編程 發布:2025-09-08 22:54:23 瀏覽:731