當前位置:首頁 » 編程語言 » 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-19 07:01:48 瀏覽:77
android把函數 發布:2025-09-19 07:01:04 瀏覽:283
垃圾站源碼 發布:2025-09-19 06:42:30 瀏覽:156
java按鈕事件 發布:2025-09-19 06:29:45 瀏覽:457
文件夾用處 發布:2025-09-19 06:21:42 瀏覽:88
php數組位置 發布:2025-09-19 06:06:45 瀏覽:865
伺服器光口配ip 發布:2025-09-19 05:48:37 瀏覽:848
phpmongodb擴展 發布:2025-09-19 05:35:23 瀏覽:778
停資料庫監聽 發布:2025-09-19 05:35:14 瀏覽:47
裸車後需要什麼配置 發布:2025-09-19 05:34:38 瀏覽:188