与我的问题here相关:以下代码
sprintf(buffer, "%-16s%-224s%-8s%-8s", "set", "ravi", "26", "60");
...填补空白区域。我需要填充'\0'
字符而不是空格。这可以实现吗?
答案 0 :(得分:1)
您可以通过以下循环实现此目的:
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';
}