gpt4 book ai didi

c - 从C中的字符串中删除空格

转载 作者:太空宇宙 更新时间:2023-11-04 05:14:56 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
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--);

但它会删除所有空格。

我该如何解决?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com