c语言文件打开和调用

实例:


#include <stdio.h>
 
int main()
{
	FILE *fpWrite=fopen("hello.txt","w");
	if(fpWrite==NULL)
	{
		return 0;
	}
	for(int i=0;i<10;i++)
		fprintf(fpWrite,"%d ",i);
	fclose(fpWrite);
	//下面是调用
	int a[10]={0};
	FILE *fpRead=fopen("hello.txt","r");
	if(fpRead==NULL)
	{
		return 0;
	}
	for(int i=0;i<10;i++)
	{
		fscanf(fpRead,"%d ",&a[i]);
		printf("%d ",a[i]);
	}
	getchar();
 
	return 1;
}


猜你喜欢

转载自blog.csdn.net/weixin_43215126/article/details/88053390