Pages

Monday, February 15, 2016

C program to write a word in text file.

#include <stdio.h>
#include <string.h>
int main()
{
FILE *fp;
char str[80];
fp = fopen("test.txt", "w+");
printf("Enter your message:");
gets(str);
fprintf(fp, "%s",str);
printf("Your message is written in test.txt file.");
fclose(fp);
//File validation is to be performed...
   return 0;
}


Output of program

Enter your message:hello student
Your message is written in test.txt file.


No comments:

Post a Comment