Ví dụ đọc ghi file text 2

Ví dụ đọc ghi file text

#include<stdio.h>
int main(void)
{
	FILE *fp;
	int i;
	char s[256];
	fp = fopen("vanban.txt","w");
	
	i=0;
	while(1)
	{
		i++;
		printf("Nhap dong thu %d(nhan Enter de ket thuc):",i);
		fflush(stdin);
		gets(s);
		if (s[0]=='\0') break;
		if (i>1) fputc(10,fp);
		fputs(s,fp);
	}
	fclose(fp);	
	printf("Van ban da nhap la:\n");
	fp = fopen("vanban.txt","r");
	while (!feof(fp))
	{
		fgets(s,256,fp);
		printf("%s",s);
	}
	fclose(fp);
	return 0;	
}	

Last updated