可能重複:
How do I trim leading/trailing whitespace in a standard way?去掉空格
我需要從開始和字符串實例的結尾刪除所有空格,如果我的字符串
" hello world. "
(不帶引號),我需要打印
"hello world."
我想是這樣的:
size_t length = strlen (str);
for (newstr = str; *newstr; newstr++, length--) {
while (isspace (*newstr))
memmove (newstr, newstr + 1, length--);
但它刪除所有空格。
我該如何解決?
的可能的複製http://stackoverflow.com/questions/122616/painless-way-to-trim-leading-trailing-whitespace-in-c和http://stackoverflow.com/questions/656542/trim-a-string-in-c – lhf
這是功課嗎? –
請參閱此SO問題的答案:http://stackoverflow.com/questions/122616/painless-way-to-trim-leading-trailing-whitespace-in-c –