Use fputs to write text string to a stream
Syntax
C fputs function has the following syntax.
int fputs(const char *str, FILE *stream);
Header
C fputs function
is from header file stdio.h
.
Description
C fputs function writes text string to the stream.
The string's null terminator is not written. This function returns nonnegative on success or EOF on failure.
If the stream is opened in text mode, the character translations may take place. If the stream is opened in binary mode, no character translations will occur.
Example
Use C fputs function to write text string to a stream.
#include <stdio.h>
#include <stdlib.h>
//from w w w .j av a 2 s. c o m
int main(void)
{
FILE *fp;
if((fp=fopen("test", "wb"))==NULL) {
printf("Cannot open file.\n");
exit(1);
}
fputs("this is a test from java2s.com", fp);
fclose(fp);
}