Tagged: C fputs

c programming write text 2

Program to write a text to a file

We will write a program in C that will accept a string from the user and write the string in a file. In this program, we will use fopen function in order to open a file. We will also use fputs function which will write a string to a file. Below is the program: #include<stdio.h> #include<conio.h> void main() { char *str; FILE *fp; //Open the file in write mode fp = fopen(“write.txt”, “w”); printf(“Enter a string: “); gets(str); //write string in a file fputs(str, fp); getch(); } C Programming is brought you by LearnCOnline.com