#include <stdio.h>
#include <string.h>
int main()
{
int n,len;
char buf[100]={0};
FILE* fp = fopen("test.txt","w");
if(fp == NULL)
{
printf("file open error");
return 0;
}
printf("input the number of lines to be written:");
scanf("%d",&n);
getchar();
while(n)
{
gets(buf);
len = strlen(buf);
buf[len] = '\n';
len++;
buf[len] = 0;
fwrite(buf,1,strlen(buf),fp);
n--;
}
fclose(fp);
return 0;
}