gpt4 book ai didi

c - 斯普林特夫 : pad with '\0' character instead of space

转载 作者:行者123 更新时间:2023-11-30 15:47:16 25 4
gpt4 key购买 nike

与我的问题相关here :以下代码

sprintf(buffer, "%-16s%-224s%-8s%-8s", "set", "ravi", "26", "60");

...填充空白区域。我需要用 '\0' 字符而不是空格填充。这能实现吗?

最佳答案

您可以通过以下循环实现此目的:

int i;
sprintf(buffer, "%-16s%-224s%-8s%-8s", "set", "ravi", "26", "60");
for (i=0;i<sizeof(buffer);i++)
{
if (buffer[i] == ' ') buffer[i] = '\0';
}

关于c - 斯普林特夫 : pad with '\0' character instead of space,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17551160/

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