C Library Function - fputs()
Description
C Library Function **int fputs(const char str, FILE stream) Write the string to the specified stream stream, without the null character.
Declaration
Below is the declaration of the fputs() function.
int fputs(const char *str, FILE *stream)
Parameters
- str -- This is an array containing the null-terminated sequence of characters 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 nonnegative value, or EOF if an error occurs.
Example
The following example demonstrates the use of the fputs() function.
#include
int main ()
{
FILE *fp;
fp = fopen("file.txt", "w+");
fputs("这是 C 语言。", fp);
fputs("这是一种系统程序设计语言。", fp);
fclose(fp);
return(0);
}
Let's compile and run the above program; this will create the file file.txt, with the following content:
这是 C 语言。这是一种系统程序设计语言。
Now let us use the following program to view the content of the file above:
#include
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);
}
C Standard Library -