gpt4 book ai didi

c - 将数组写入文本文件

转载 作者:行者123 更新时间:2023-11-30 18:41:14 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com