C fputs() function : <stdio.h>


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 ?
  1. fputs outputs a string to a stream
  2. 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.
  3. On success, fputs returns the last character written.
  4. 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 : 

  1. op.txt File is Opened into Write Mode
  2. Write “Hello World” to op.txt File

Bookmark & Share