Fputs : Write Line of Character to File
Fputs : Write Line of Character to File
Syntax :
#include<stdio.h>
int fputs(const char *str, FILE *stream);str - String to be Written on Stream
*Stream - File Pointer
What it does ?
- fputs outputs a string to a stream
- fputs copies the null-terminated string s to the given output stream. It does not append a newline character, and the terminating null character is not copied.
- On success, fputs returns the last character written.
- On error, fputs returns EOF.
Live Example :
#include<stdio.h>
int main(void)
{
/* write a string to standard output */
fputs("Hello worldn", stdout);
return 0;
}Header File : stdio.h
How to Write to File using fputs ?#include<stdio.h>
int main(void)
{
FILE *fp;
fp = fopen("op.txt","w");
fputs("Hello worldn",fp);
return 0;
}Output :
- op.txt File is Opened into Write Mode
- Write “Hello World” to op.txt File
Bookmark & Share