可能重复:
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 –