Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的 C 程序中,我正在使用命令终端打印一个字符串,printf("%d %s %s\n", node->id, node->date, node->input);但我现在需要使用 write 函数write(STDOUT_FILENO, cmdline, strlen(cmdline));......
printf("%d %s %s\n", node->id, node->date, node->input);
write(STDOUT_FILENO, cmdline, strlen(cmdline));
如何像使用 printf 一样格式化字符串?
使用sprintf/snprintf将字符串格式化为字符缓冲区,然后write使用它。
sprintf
snprintf
write