怎么把一段字输出到文档上面,我这个为什么输出不了,文档还是空的

img


#include <stdio.h>

int main()
{
    FILE* f = fopen("D:/document/test.txt", "w+");
    char s[] = { "12345" };
    if (f == NULL)
    {
        printf("open error!\n");
        return 0;
    }
    fprintf(f, "%s", s);
    fclose(f);
    return 0;
}

img


路径的错误吧

修改如下,供参考:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    char s[] = { "12345" };
    FILE* f1 = fopen("D:\\f1.txt", "w+");
    if (f1 == NULL){
        printf("Fail to open file!\n");
        //exit(0);
    }
    else{
        fprintf(f1, "%s", s);
        fclose(f1);
    }
    return 0;
}

如果路径里写/,那么只应该写一个
如果你写\,那么就要写2个
/不是转义符呀
你写//那代表路径中间有个文件夹名字是空