Linux C string output function puts (), fputs (), printf () detailed

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.