gpt4 book ai didi

c - 从程序中删除 '\n'

转载 作者:行者123 更新时间:2023-12-04 11:15:13 24 4
gpt4 key购买 nike

system(do_this); // which executes an external program to output a phrase on the screen
printf("=My taxes");

输出:

500$

=My taxes

预期输出:

500$=My taxes

我无法控制 do_this 中执行的代码,它会自动输出 '\n'

最佳答案

这应该有效:

system("program | tr -d '\012\015'");
printf("=My taxes\n");

program 是您要运行的程序。 tr 命令从程序 的输出中删除所有 CR 和 LF 字符(八进制代码 015 和 012)。该解决方案假定程序 仅输出一行(您的税),并且它适用于行尾为 CR、LF、CR+LF、LF+CR 的系统(包括所有广泛使用的操作系统,如 MacOS、Linux 和Windows)。

关于c - 从程序中删除 '\n',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8144221/

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