C library function -fputs()
C Standard Library - <stdio.h>
Description
C Library Functionsint fputs(const char *str, FILE *stream)Writes the string to the specified stream, not including the null character.
Declaration
Below is the declaration of the fputs() function.
int fputs(const char *str, FILE *stream)
Parameter
- str-- This is an array containing the null-terminated character sequence to be written.
- stream-- This is a pointer to a FILE object that identifies the stream to which the string is to be written.
Return Value
This function returns a non-negative value, or returns EOF if an error occurs.
Example
The following example demonstrates the usage of the fputs() function.
#include <stdio.h>
int main ()
{
FILE *fp;
fp = fopen("file.txt", "w+");
fputs("这是 C 语言。", fp);
fputs("这是一种系统程序设计语言。", fp);
fclose(fp);
return(0);
}
Let us compile and run the above program, which will create a filefile.txt, and its content is as follows:
这是 C 语言。这是一种系统程序设计语言。
Now let's use the following program to view the contents of the above file:
#include <stdio.h>
int main ()
{
FILE *fp;
int c;
fp = fopen("file.txt","r");
while(1)
{
c = fgetc(fp);
if( feof(fp) )
{
break ;
}
printf("%c", c);
}
fclose(fp);
return(0);
}
other extensions