C语言文件读写

#include<stdio.h>


int main()

{

	int age=0;
	FILE *file =NULL;


	file=fopen("test.txt","r+");
	//rename("test.txt","xinhai.txt");
	
	if(file!=NULL)
	{
	printf("The file can be opened.");
	fputc('A',file);
	fputc('\n',file);
	fputs("come on",file);
	
	
	printf("您多少岁?\n");
	scanf("%d",&age);
	fprintf(file,"使用者年龄是%d岁",age);
	
	
	fclose(file);
	}
	
	
	else
	{
	printf("The file can't be opened.");
	}
	remove("test.txt");
	return 0;

}

猜你喜欢

转载自blog.csdn.net/Gnewocean/article/details/82817172