Home » C programs » stdio.h header file functions

fputs() function in C language with Example

Here, we are going to learn about the fputs() function of library header stdio.h in C language with its syntax, example.
Submitted by Souvik Saha, on January 11, 2019

fputs() function in C


    int fputs(const char *string,FILE *filename);


    const char *string,FILE *filename

Return type: int

Use of function:

In the file handling, through the fputs() function we take the string from the user and store it to the input stream and increments the file pointer indicator for accepting next string input. The prototype of the function fputs() is: int fputs(const char *string,FILE *filename);

It returns the negative value on success and return EOF for failure. Here string is the array of character and filename is the name of the file stream.

fputs() example in C

#include <stdio.h>
#include <stdlib.h>

int main(){
	//Initialize the file pointer
	FILE *f;							
	//Take a array of characters 
	char ch[100];						

	//Create the file for write operation
	printf("Enter five strings\n");
	for(int i=0;i<4;i++){
		//take the strings from the users
		//write back to the file
		//every time take a new line for the new entry string 
		//except for last entry.Otherwise print the last line twice
		//clear the stdin stream buffer
	//take the strings from the users
	//close the file after write operation is over

	//open a file
	printf("\n...............print the strings..............\n");
		//takes the first 100 character in the character array 
		//and print the strings
	//close the file

	return 0;


fputs example in c

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.