First, puts () function of the detailed
The puts () function is used to write a string to a standard output device (screen) and wrap it in a format called:
puts (s);
where S is a string variable (string array name or string pointer).
The puts () function works the same as the language printf ("%s\n", s) .
#include <stdio.h> #include <string.h>int main (int argc, char **argv) {char s[20], *f;strcpy (S, "Hello world!") ;//string array variable assignment f = "Thank you";//String pointer variable assignment puts (s);p UTS (f); return 0;}
Description
(1) the puts () function can only output strings and cannot output numeric values or format transformations.
(2) You can write the string directly into the puts () function. Such as:
Puts ("Hello, Turbo C2.0");
Second, fputs () function of the detailed
Prototype:
int fputs(const char * s,file * stream);
Function Description:
Writes the specified string to the file stream, does not contain the string terminator ' \ S ', the return value is a character, and the return value is EOF when an error occurs, which can be used to replace the data in the file stream, but cannot be added .
Example:
#include <stdio.h>int main (int argc, char **argv) {FILE *fp;char *filename = "/users/jianbao/clionprojects/apue/ 123.txt "; fp = fopen (filename," r+ "); Fseek (FP, 3, seek_cur); Fputs (" Insert Strings. ", FP); return 0;}
Original file content:
1234
Second line. Second Strings.
Modified file content:
123Insert Strings. Second Strings.
As you can see, replace "\ n and second line." In the original file with "Insert Strings."
Linux C string output function puts (), fputs (), printf () detailed