嘿。 我正在制作一份应该能够打印出来以添加签名的文档。我在 C 程序的输出中有该文档,但是保存时我只得到代码,而不是最终输出。 这是我的代码:
#include <stdio.h>
int main(void)
{
FILE*pfile=NULL;
pfile=fopen("MY_FILE","r");
printf("Digital Forensics Investigation Documentation Evidence Form\n\n");
printf("Section 1: Evidence Item Record\n");
printf("---------------------------------\n");
char array1[20][100]={"\nLab reference Number:","\nCase reference Number:","\nItem reference Number:","\nDevice Description:","\nAdditional Information:","\nSection 2: Investigator Details\n\nDevice accepted by:","\nDate and time received:","-------------------------------------------------------------------------","\n\nSignaure:\n","\n\n------------------"};
char array2[20][500]={"TDI-DF","DFI-C001-2014-10-108","EI-201","Western Digital external hard drive,1TB","\nBlack case,with a few scratches on the side and chipped corner.\nNo obvious serial number or other distinguising features.\nPower cable and USB cable still attached.\nReceived from CTO organisation.\nIt was attached to a laptop running windows 8.\nThis laptop was powered of at the time this harddrive was removed.\n\n-------------------------------------------------------------------------","Sara Hansen","30th December 2014 at 15:00"};
int i;
for (i=0;i<20;i++)
{
printf("%s %s \n", array1[i], array2[i]);
}
fscanf(pfile,"d% d% d%");
fclose(pfile);
return 0;
}
我希望我的输出保存在文本文档asell中,而不仅仅是代码中。
任何人都可以帮我找出我的代码中缺少的内容,以便将其以正确的格式保存在文本文件中吗?
谢谢!
最佳答案
您需要使用 w
模式和 fopen
才能编写:
pfile = fopen("MY_FILE", "w");
然后使用fprintf
代替printf
,例如:
fprintf(pfile, "Digital Forensics Investigation Documentation Evidence Form\n\n");
不确定您的 fscanf
行正在尝试完成什么任务。
关于c - C语言中如何将输出自动存储到文本文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27742167/