Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char* retrieve(char*s)
- {
- int cnt=0;
- while(*s++) //到*s == '\0' 時停止
- ++cnt; //計算有幾個字元
- s -= cnt; //因為s已經指到'\0'了,所以要將位址還原
- char*t = (char*)malloc(cnt+1); //新增一個空間來放置處理過的字串
- char*dest=t;
- for( ;*s; ++s) //依照題意過濾字元
- if(*s<='9'&&*s>='0' || *s=='+' || *s=='-' || *s=='.')
- *t++ = *s;
- *t=0; //擺放結尾'\0'
- return dest; //回傳改變過的字串
- }
Add Comment
Please, Sign In to add comment