c - 将数组写入文本文件

标签 c arrays file file-io

我正在尝试将字符数组写入txt 文件。我自己找不到错误。这应该工作得很好,但是,此代码不会将我想要的数组写入 txt 文件。即使我想覆盖一个txt文件,它也只是写入空白字符。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main(void){

   char temp[] = "Print newline, word, and byte counts for each FILE, and a total if more than one FILE is specified. With no FILE, or when FILE is a dash (\"-\"), wc operates on standard input. (A word is a non-zero-length sequence of characters delimited by white space.)";

   FILE *fpw = fopen("output.txt","w");
   if(ferror(fpw)) printf("Error");

   fputs(temp,fpw);
   fclose(fpw);

}

最佳答案

临时字符串中有 "字符。使用反斜杠将其转义,如下所示:

char temp[] "String with \"'s in it.";

关于c - 将数组写入文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22577754/

相关文章:

c - 如何用 C 语言为 HengSTLer C51 热敏票据打印机编程

Linux 上的 CommandLineToArgvW 等效项

javascript - 如何合并这些复杂的 JavaScript 数组对象?

c - 试图创建一个结构,不让我输入字符串

c - 很难弄清楚 C 中的函数

c - 绕过内存损坏限制

arrays - 在 Ruby 中将数组转换为索引哈希

Java:数据文件的相对路径

整个文件的 Java BufferedWriter 精度

java - 无法在文件浏览器中查看所有文件