SLIDE1

Thursday, January 8, 2015

ghi chuổi lên file đến khi chuổi nhập vào là rỗng thì kết thúc

//ghi chuổi lên file đến khi chuổi nhập vào là rỗng thì kết thúc
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
FILE *t;
char s[100];
t=fopen("E:\\toan.txt","w");
if(t==NULL)
{
printf("error");
exit(0);
}
printf("nhap chuoi:\n");
do
{
gets(s);
if(strlen(s)==0)break;
fputs(s,t);
fputs("\n",t);
}while(strlen(s)>0);
fclose(t);
}