Wednesday, April 18, 2012

WRITING OF STRINGS 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();
}

No comments:

Post a Comment