C language fgets (...) Read input from stream, opposite fputs (...) Writes data to a file.
for ANSI C programs, the runtime system opens at least three streams, including the following 3 streams:
1. Standard input standard inputs. The standard definition is stdin.
2 standard output standard outputs. Standard defined as stdout
3. Standard error Standard. The standard is defined as stderr.
at the same time, use the file structure to point to these three streams.
fputs (...) Used to write data to these three streams.
prototype int fputs (char *s, FILE *stream);
S is a character pointer, which can be either a character array or a character pointer, or you can use a string constant as a parameter.
Example:
FILE *fp=fopen ("Test.txt", "w");
char s1[20]= "Hello World";
char *s2= "Hello C";
fputs (S1,FP); Array name
fputs (S2,FP); Character Pointer
fputs ("Hello", FP); String Constants
The above three usages are all OK, in essence, the direct value of string in C language is actually a pointer.
return Value:
If the write succeeds, a non 0 is returned, at which point the compiler defaults to return 1.
If an error is written, EOF is returned.
Note: Once the fputs (char *s, file *stream) function writes data to a file, the file position pointer automatically moves backwards.
fputs (...) Output data to the screen.
Since the file structure can point to three streams, you can point to the stdout stream as well
so:
fputs ("Hello World", stdout);
just want the screen to output Hello Word.
Finally, look at the fputs (...) The standard library implementation of the function:
int fputs (char *s, FILE *stream)
{
int C;
while (c =*s++)//From here you can see that fputs does not write to the stream the null character at the end of the string.
PUTC (c,stream);
return ferror (stream)? EOF: Non-negative
}