我有兴趣清除用printf语句生成的C程序的输出,多行很长.
我最初的猜测是使用
printf("output1\n");
printf("output2\n");
rewind(stdout);
printf("output3\n");
printf("output4\n");
Run Code Online (Sandbox Code Playgroud)
但这会产生
output1
output2
output3
output4
Run Code Online (Sandbox Code Playgroud)
我希望它会产生
output3
output4
Run Code Online (Sandbox Code Playgroud)
有谁知道如何获得后者的结果?
我在Objective-C中创建一个基于控制台的应用程序,它依赖于能够定期清除控制台.如何才能做到这一点?我在SO和Google上看到的只是让开发人员用X-Code清除控制台的方法,但那是行不通的.
我在Yahoo!上找到的一个解决方案 答案告诉我要执行以下操作,但由于无法找到文件而无法运行:
NSTask *task;
task = [[NSTask alloc]init];
[task setLaunchPath: @"/bin/bash"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: @"clear", nil];
[task setArguments: arguments];
[task launch];
[task waitUntilExit];
Run Code Online (Sandbox Code Playgroud)