[已解決]怎麼轉變字串?

Home Home
引用 | 編輯 jim28791
2007-06-07 12:17
樓主
推文 x0
有一題是要將字串str[]="I $%am 5a%$ good#@$ student"轉變成 ..

訪客只能看到部份內容,免費 加入會員



獻花 x0
引用 | 編輯 ety
2007-06-07 19:19
1樓
  
用count的方式來累加?
不明白你的意思, 方便看一下你的 source code 嗎?

獻花 x0
引用 | 編輯 ety
2007-06-07 19:24
2樓
  
字串的輸出是不是只許可字母與空白? 其它符號都忽略? 數字是否輸出?

你只要判斷其 ASCII 是否在 65~90 與 97~122 這兩個區間就好了, 是就輸出, 不是就忽略, 空白鍵好像是 32, 我也不太清楚, 你可以再查證!

獻花 x0
引用 | 編輯 jim28791
2007-06-07 21:03
3樓
  
拍謝~~我說明不清楚~~
我後來想到...
可以這樣用~~


#include <stdio.h>
#include <string.h>
#include <ctype.h>



int main(void)
{

char str[]= "I $%am 5a%$ good#@$ student";
int i;

printf("字串轉換前%s\n",str);
printf("字串轉換後\n");

for(i=0;i<strlen(str);i++)
if(isalpha((str)) !=0 )

printf("%c",str);
else
printf(" ");

return 0;
}

獻花 x0