假设我运行一个程序,该程序在其运行过程中生成多个 printf 语句。自然,每次它遇到 printf 命令时都会打印。我将如何进行而不是打印它,“存储”它,然后在程序结束时,取出所有应该打印的行,对其进行排序,然后打印它。
例如
Run Program
prints "File1 90"
prints "File2 30"
prints "File3 40"
End Program
Run Program
prints "File1 90" (don't actually print it out)
prints "File2 30" (don't actually print it out)
prints "File3 40" (don't actually print it out)
Take print statements and rearrange them by numerical order, then print
Program prints:
prints "File2 30"
prints "File3 40"
prints "File1 90"
我想我必须在我的 C 程序中使用 unix shell 命令,例如
sort -k2n,2 -k1,1 myprogram