我正在尝试将字符数组写入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);
}
答案 0 :(得分:3)
你有“临时字符串中的字符。用反斜杠逃脱它们,像这样:
char temp[] "String with \"'s in it.";