Write to text file

Write to text file

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C programming concepts. You can learn C language at your own speed and time. One can learn concepts of C language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Write to text file
Write to text file

Write a C program to text file

PROGRAM: 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;
}

Leave a Reply

Your email address will not be published. Required fields are marked *