c - C语言中如何将输出自动存储​​到文本文件中?

标签 c

嘿。 我正在制作一份应该能够打印出来以添加签名的文档。我在 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/

相关文章:

c - 二进制文件写入/读取问题

c - 动态改变 Material 的颜色

c - hiredis 命令对简单 C 代码的空回复

c - 如何使用英特尔内在函数从 256 个 vector 中提取 8 个整数?

c - 查找C中的内存泄漏

php - 在 lampp 服务器中从 php 运行 ffmpeg 时找不到 GLIBCXX_3.4.9

c - 在 main 中声明的函数原型(prototype) - 最佳实践?

c++ - 如何告诉 lcov 忽略源文件中的行

c - 从C中的文本文件中读取unicode字符

c - 与 openssl 库交叉编译时 undefined reference 错误