Printf, fprintf, sprintf, snprintf, vprintf, vfprintf, vspri

Source: Internet
Author: User

Reference: http://blog.sina.com.cn/s/blog_674b5aae0100prv3.html

Overview (SYNOPSIS)

# Include <stdio. h>

Int printf (const char * format ,...);

Int fprintf (FILE * stream, const char * format ,...);

Int sprintf (char * str, const char * format ,...);

Int snprintf (char * str, size_t size, const char * format ,...);

# Include <stdarg. h> ------------ it seems that all of them are declared in stdio. h.

Int vprintf (const char * format, va_list ap );

Int vfprintf (FILE * stream, const char * format, va_list ap );

Int vsprintf (char * str, const char * format, va_list ap );

Int vsnprintf (char * str, size_t size, const char * format, va_list ap );

Description (DESCRIPTION)

Print functions generate output content based on the format parameter.

The printf and vprintf functions write the output content to stdout, that is, the standard output stream;

The fprintf and vfprintf functions write the output content to the given stream;

The sprintf, snprintf, vsprintf, and vsnprintf functions store the output content in the str string ..

These functions control the output content by the format string format parameter, which indicates how to convert the following parameters (or parameters accessed through stdarg (3)'s variable length parameter mechanism) into output content.

These functions return the number of printed characters (excluding '\ 0' at the end of the string '). The output of snprintf and vsnprintf does not exceed the size byte (including '\ 0' at the end). If the output content is truncated due to this restriction, the function returns-1. (This sentence is incorrectly interpreted. You can refer to the man Manual. The original Article describes the returned values as follows :)

Return value
Upon successful return, these functions return the number of characters
Printed (not including the trailing '\ 0' used to end output
Strings). The functions snprintf () and vsnprintf () do not write more
Than size bytes (including the trailing '\ 0'). If the output was trun-
Cated due to this limit then the return value is the number of charac-
Ters (not including the trailing '\ 0') which wowould have been written
The final string if enough space had been available. Thus, a return
Value of size or more means that the output was truncated. (See also
Below under NOTES.) If an output error is encountered, a negative
Value is returned.

It can be seen from the manual that if the output is truncated due to the size limit, the return value is the number of characters (not including '\ 0') in str after being truncated and written, and the premise is that str has sufficient available space.

If an error occurs in the output, a negative value is returned. This sentence is for the above eight functions.

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.