Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C-fprintf未写入文件_C_Unix_Clang_Freebsd - Fatal编程技术网

C-fprintf未写入文件

C-fprintf未写入文件,c,unix,clang,freebsd,C,Unix,Clang,Freebsd,C-fprintf没有写入文件,知道为什么吗 #include <stdio.h> #include <stdlib.h> int main(void){ FILE* pfile=fopen("/home/user-vlad/Programming/C-other/meme.txt","r"); if(pfile==NULL){ printf("ERROR: Stream is equal to NULL\n"); exit

C-fprintf没有写入文件,知道为什么吗

#include <stdio.h>
#include <stdlib.h>
int main(void){
    FILE* pfile=fopen("/home/user-vlad/Programming/C-other/meme.txt","r");
    if(pfile==NULL){
        printf("ERROR: Stream is equal to NULL\n");
        exit(1);
    }
    fprintf(pfile,"Hello");
    fclose(pfile);
    return 0;
}

编译器:clang,OS:FreeBSD

假设文件打开可能是因为您使用参数r调用了fopen,这意味着读取

在写作时,你可以使用w参数

或者,如果文件已经存在,则为r+

或者,如果文件已经存在,并且您想要追加,则可以使用


您可以在fopen上了解更多信息。

否,该文件已存在。我只想fprintf写入一个已经存在的文件。@CIAAbigguy然后你可以使用r+,虽然写入一个新文件并打印到它确实有效,但我想添加到文件中,而不是覆盖它,在这种情况下,我有文本,我想写入一个包含hello的文件,然后放置单词,世界进入it@CIAAbigguy请阅读fopen的手册页。这里描述了所有选项。您只打开了该文件进行读取。阅读第二个参数和第二个参数的含义。r表示你只想阅读。有写入、追加等选项。当fopen错误发生时,如果pfile为NULL,则使用“perror”,因为该错误的系统消息将追加到放置在参数之间双引号中的文本中。即perror fopen fo meme.txt失败;
fopen("/home/user-vlad/Programming/C-other/meme.txt","w");
fopen("/home/user-vlad/Programming/C-other/meme.txt","r+");
fopen("/home/user-vlad/Programming/C-other/meme.txt","a");