gpt4 book ai didi

c - 如何去掉字符串开头的 '\n'

转载 作者:行者123 更新时间:2023-11-30 21:43:24 26 4
gpt4 key购买 nike

这是字符串 char temp[] = "\nHello";

如何去掉字符串开头的\n

最佳答案

您可以使用标准 C 函数 memmove。例如

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

int main( void )
{
char temp[] = "\nHello";

if (temp[0] == '\n')
{
memmove(temp, temp + 1, strlen(temp));
}

puts(temp);
}

关于c - 如何去掉字符串开头的 '\n',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44553491/

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