如何使用文件处理在c中创建文件? [英] how to create file in c using file handling?

查看:61
本文介绍了如何使用文件处理在c中创建文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在c中创建文件时。

代码是编译运行但文件没有创建...

我的代码如

  #include   <   stdio.h  >  
void main()
{
FILE * FP;
fp = fopen( first.txt W);
fprintf(fp, fprintf的第一个文件...... \ n);
fclose(fp);
}



并且它在consleNull指针assingnment

解决方案

上给出错误首先, C区分大小写:所以 FP fp不一样

始终复制并且粘贴您的代码,以便我们知道 完全 您正在运行的代码 - 这将无法编译...



但假设已经修复,tgf很可能是fopen返回 null ,因为它无法打开for。这可能适合任何原因,其中大部分原因与文件系统有关。

因此,请指定要使用文件名创建的文件夹,并确保该文件夹具有相应的权限

when i am creating file in c.
code is compile and run but file is not creating...
my code like

#include <stdio.h>
void main()
{
    FILE *FP;
    fp = fopen("first.txt","W");
    fprintf(fp, "first file by fprintf...\n");
    fclose(fp);  
}


and it gives error on consle "Null pointer assingnment"

解决方案

Firstly, C is case sensitive : so FP is not the same as fp
Always copy and paste your code so we know exactly what code you are running - that won't compile...

But assuming that's fixed, tgf chances are that the fopen is returning null because it can't open the for. That may be fit any of many reasons, most of which are to do with the file system.
So specify the folder you want to create with the file name, and make sure the folder has the appropriate permissions.


这篇关于如何使用文件处理在c中创建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆