Clear, practical technology insights About · Contact

Function Fputs ()() in C

Explore Function Fputs ()() in C with clear explanations, practical examples, and useful tips.

Published: 3 minutes read
Table of Contents

This guide covers function fputs ()() in c with practical context and easy-to-follow details. Use it to understand the subject and apply the information confidently.

Declare Function Fputs ()() in C

Below is the declaration for fputs () in C:

 int fputs ( const char * str , FILE * stream ) 

Parameters

Str - This is an array containing the sequence of characters ending with null written.

Stream - This is the pointer to a FILE object that identifies the Stream, where the string is written.

Returns the value

This function returns a non-negative value, or returns EOF if there is an error.

For example

The following program C illustrates the usage of fputs () in C:

 #include int main () { FILE * fp ; fp = fopen ( "baitapc.txt" , "w+" ); fputs ( "Hoc c co ban va nang cao tai QTM." , fp ); fputs ( "Loat bai thu vien C chuan." , fp ); fclose ( fp ); return ( 0 ); } 

Compiling and running the above program will create a baitcap. Txt in the current directory.

Now follow the contents of the above file by using the following C program:

 #include int main () { FILE * fp ; int c ; fp = fopen ( "baitapc.txt" , "r" ); while ( 1 ) { c = fgetc ( fp ); if ( feof ( fp ) ) { break ; } printf ( "%c" , c ); } fclose ( fp ); return ( 0 ); } 

Compile and run the above program to see the results.

According to Tutorialspoint

Last lesson: Function fputc () in C

Next lesson: Function getc () in C

Frequently Asked Questions

What should I check before following these steps?

Confirm device and software compatibility, save important data, and make sure you have the required permissions, files, and account access.

Why might the process not work?

Common causes include outdated software, missing permissions, incompatible hardware, an unstable connection, or completing a step in the wrong order.

Can I undo the changes if necessary?

That depends on the tool or setting. Use built-in restore options when available, keep a backup, and record the original configuration first.

Was this article helpful?

Your feedback helps us improve.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.