Friday 23 September 2016

Write to text file

/* Write to text file */

#include<stdio.h>
int main()
{
FILE *fp;
char mystr[100];

fp=fopen("mytext.txt","w");
if(fp==NULL)
{
puts("Some error occured.");
return 1;
}

printf("\nEnter some lines:\n");
while(strlen(gets(mystr))>0)
{
fputs(mystr,fp);
fputs("\n",fp);
}
fclose(fp);
return 0;
}

No comments:

Post a Comment

Featured post

The Thrill of Programming: Exploring the Satisfaction Behind the Code

Different individuals find satisfaction in programming for various reasons. Here are some common factors that tend to bring satisfaction to ...