當前位置:首頁 » 編程語言 » 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-07-03 03:22:49 瀏覽:22
中國電信加密通信業務 發布:2025-07-03 03:06:00 瀏覽:520
腳本家的台詞 發布:2025-07-03 03:05:50 瀏覽:708
arcgisforpython 發布:2025-07-03 03:05:46 瀏覽:898
期計演算法 發布:2025-07-03 02:56:53 瀏覽:404
不同域訪問 發布:2025-07-03 02:49:05 瀏覽:818
多槽編程 發布:2025-07-03 02:47:42 瀏覽:919
sql2008錯誤233 發布:2025-07-03 02:28:52 瀏覽:168
創建資料庫語句mysql 發布:2025-07-03 02:14:34 瀏覽:146
python量化投資 發布:2025-07-03 02:05:11 瀏覽:804