繁体   English   中英

有没有办法获取cmd提示的文本文件? 也就是说,printf在代码块c中显示的所有数据?

[英]is there a way to get a text file of the cmd prompt? that is, all the data that printf shows in codeblocks c?

我目前正在使用代码块在c语言中编写大量计算,并使用printf()将它们打印到cmd提示符下; 功能。 我正在尝试从收集的数据创建图形。 有没有办法获得我打印出的所有数据的纸质副本或文本/ doc文件,或者更好的方法?有没有办法将cmd提示符下的所有值都变成图形?

您为什么不将它们保存到文件中?

写入文件的好例子:

FILE *f = fopen("file.txt", "w");
if (f == NULL)
{
   printf("Error opening file!\n");
   exit(1);
}

 /* print some text */
 const char *text = "Write this to the file";
 fprintf(f, "Some text: %s\n", text);

/* print integers and floats */
int i = 1;
float py = 3.1415927;
fprintf(f, "Integer: %d, float: %f\n", i, py);

/* printing single chatacters */
char c = 'A';
fprintf(f, "A character: %c\n", c);

fclose(f);

另一种解决方案是使用> file.txt通过管道传递输出

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM