本文目錄一覽:
- 1、尋找一個c語言程序:從輸入中過濾字元串?
- 2、c語言初學 如何過濾字元串中除了字母與數字中的字元 例如我輸入123abcABC!@#123 輸
- 3、C語言怎麼編寫:請編寫一個字元串過濾程序,若字元串中出現多個相同的字元,將非首次出現的字元過濾掉。
尋找一個c語言程序:從輸入中過濾字元串?
可以直接定義一個字元類型,然後用gets(),從鍵盤得到這個字元串,再這個字元串進行遍歷解析
下面提供一個例子:從鍵盤輸出一串字元並且輸出其中的數字
#include stdio.h
#include stdlib.h
#include string.h
int main(void) {
char string[100];
int i;//循環變數
gets(string);
for (i = 0; i strlen(string); i++) {
if((string[i]=’0′)(string[i]=’9′)){//判斷每個字元是否是0~9直接的數
printf(“%c”,string[i]);//是數字的話直接列印
}
}
puts(“”);
puts(“end”);
return EXIT_SUCCESS;
}
c語言初學 如何過濾字元串中除了字母與數字中的字元 例如我輸入123abcABC!@#123 輸
void fun(char a[], int len)
{
int i, j=0;
char *str = (char *)malloc(sizeof(char)*(len+1));
for(i=0; ilen; ++i)
{
if((‘1’=a[i] a[i]=’9’) || (‘a’=a[i] a[i]=’z’) ||(‘A’=a[i] a[i]=’Z’))
str[j++] = a[i];
}
str[j] = ‘\0’;
strcpy(a, str);
free(str);
}
C語言怎麼編寫:請編寫一個字元串過濾程序,若字元串中出現多個相同的字元,將非首次出現的字元過濾掉。
結果出來了,你看看吧,滿意請採納
#include stdio.h
#include string.h
void finddd(char x[]);
int main()
{
char a[150];
char *aa;
int a1;
int i;
printf(“請輸入任意的字元串: “);
gets(a);
finddd(a);
return 0;
}
void finddd(char x[]) // 不帶數據返回
{
int i,shu=0;
char aa[100];
int aaa[200]={0};
for(i=0;istrlen(x);i++)
{
if(aaa[ x[i] ] == 0)
{
aaa[ x[i] ] = 1;
aa[shu++]=x[i];
}
}
aa[shu++]=’\0′;
printf(“剔除重複字元後的字元串: %s\n”,aa);
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/288750.html