1. 程式人生 > >C語言檔案讀寫

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; }