C語言請編寫程式實現以下功能 在字串中所有數字字元前加一

時間 2021-09-21 10:01:43

1樓:問明

#include

int fun(char *s)

char t[80];

int i, j;

for(i=0; s[i]; i++)  /*將串s拷貝至串t*/t[i]=s[i];

t[i]='\0';

for(i=0,j=0; t[i]; i++)/*對於數字字元先寫一個$符號,再寫該數字字元*/if(t[i]>='0' && t[i]<='9')s[j++]='$';

s[j++]=t[i];

/*對於非數字字元原樣寫入串s*/

else

s[j++]=t[i];

s[j]='\0';  /*在串s結尾加結束標誌*/return 0;

int main()

char s[80];

printf ( "enter a string:" );

scanf ("%s", s);  /*輸入字串*/fun(s);

printf ("the result: %s\n", s);  /*輸出結果*/

return 0;

2樓:明月看盡滄桑

印象中有一個字串剪下函式,可以把字串切成2段的,把"$"字元當做第三個字串然後在拼起來,要是沒有就自己寫一個吧。

3樓:匿名使用者

#include "stdio.h"

#include "string.h"

int main()

i++;

} printf("s=%s",s);}

c語言 請編寫程式實現以下功能:在字串中所有數字字元前加一個$字元。例如, 輸入:a1b23c 20

4樓:問明

#include

int fun(char *s)

char t[80];

int i, j;

for(i=0; s[i]; i++)  /*將串s拷貝至串t*/t[i]=s[i];

t[i]='\0';

for(i=0,j=0; t[i]; i++)/*對於數字字元先寫一個$符號,再寫該數字字元*/if(t[i]>='0' && t[i]<='9')s[j++]='$';

s[j++]=t[i];

/*對於非數字字元原樣寫入串s*/

else

s[j++]=t[i];

s[j]='\0';  /*在串s結尾加結束標誌*/return 0;

int main()

char s[80];

printf ( "enter a string:" );

scanf ("%s", s);  /*輸入字串*/fun(s);

printf ("the result: %s\n", s);  /*輸出結果*/

return 0;

5樓:匿名使用者

#include

#include

#define maxlen  1000

int main()

t[tlen++] = s[i];

}t[tlen] = '\0';

printf("%s\n", t);

//如果要修改的是原始字串,就加上“strcpy(s, t);” 注意字串長度不要超過maxlen.

return 0;}

用c語言編寫程式使字串中所有數字前加$,不要用指標

6樓:于于祥祥

將輸入的字元存入一個陣列中,然後一個一個的檢測是否是數字字元,若果不是,放入另一個陣列中,如果是,將這個字元放入另一個陣列之前先放一個"$",直至全部檢測完。

7樓:匿名使用者

#include

#include

void inset(char a,int n,char c)a[n]=c;

}void main()

}printf("%s\n",str);}

8樓:匿名使用者

#include

#include

int main()}

c語言問題:在字串中的所有數字字元前加一個$字元。請問以下**錯在**

9樓:匿名使用者

strcpy函式要求兩個引數指標指向的操作空間互不重疊,否則結果是未定義的

c語言程式設計:在字串中所有數字字元前加一個$字元。如, 輸入:a1b23cd45,則輸出為:a$1 10

10樓:聽不清啊

第一個for迴圈的條件應該是s[i]!=0;下面也還有錯。

C語言請編寫程式實現以下功能 在字串中所有數字字元前加一

問明 include int fun char s char t 80 int i,j for i 0 s i i 將串s拷貝至串t t i s i t i 0 for i 0,j 0 t i i 對於數字字元先寫一個 符號,再寫該數字字元 if t i 0 t i 9 s j s j t i 對於...

VB編寫程式實現以下功能 設有二維陣列A 4,4 ,每個陣列元素為兩位的隨機正整數

private sub command1 click 交換第二列和第四列 text1.text text2.text label1.caption dim aa 1 to 4,1 to 4 as integer,bb 1 to 4,1 to 4 as integer text1.text 交換前的資...

c語言請編寫程式來幫,c語言 請編寫一個程式來幫

right prompt wrong prompt 求幫忙編一個c語言程式 本來想著給你答一下。結果發現太遲了,只是編寫了一些 你看一下。如果能用就用。還沒編譯過。一定有很多問題吧。一般 只是參考一下。或可這麼做。include define maxsize 1024 int store maxsi...