我正在尝试将字符数组写入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/