用VC写C语言 能用fopen()函数吗 ??

来源:百度知道 编辑:UC知道 时间:2024/06/10 22:53:49
我用fopen()返回了一个NULL,是什么原因???

当然可以。如
#include<stdio.h>
#include<stdlib.h>
FILE *p;//文件指针
void main()
{
char a[100];
scanf("%s",a);
if((p=fopen("c://b.txt","w+"))==NULL)//放在C盘
{
exit(1);
}
fprintf(p,"%s",a);//向文件中存数据
fclose(p);
}

可以的 vc是c++编辑器 而c++向下兼容c语言 所有基本上c语言的函数vc都可以支持

只要是C语言都包含stdlib.h这个头文件,只要有这个头文件就可以.
用的时候别忘了加文件指针!
举个例子
下面是我写的N皇后的源码

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int num=0,n;
int a[100];
FILE *g;
void arran(int k)
{
if(k>=n)
{int z;
for (z=0;z<n;z++)
fprintf(g,"%d ",a[z]+1);
fprintf(g,"\n");
num++;
}
else
{
int f=0;
for (;f<n;f++)
{
if(k==0){ a[k]=f;arran(k+1);}
else