Saturday, April 18, 2009

Writing string to a file

#include"stdio.h"
void main()
{
FILE *p;
char str[70];
if((p=fopen("string.txt","w"))==NULL)
{
printf("\nUnable to open file string.txt");
exit(1);
}
else
printf("\nEnter a set of strings,Press just enter key to finish\n: ");
while(strlen(gets(str))>0)
{
fputs(str,p);
fputs("\n",p);
}
fclose(p);
getch();
}

0 comments: