Scanf and printf

Source: Internet
Author: User
1. scanf family

1. the prototype of the scanf family is as follows. The ellipsis in each prototype represents a variable-length pointer list. Values converted from input are stored one by one to the memory locations pointed to by these pointer parameters.

Int fscanf (File * stream, char const * format ,...);

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

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

2. the above functions read characters from the input source and convert them according to the format code given by the format string.

3. Differences:

1> the Input Source of fscanf is the stream given as a parameter.

2> scanf reads data from standard input

3> sscanf reads characters from the string given by the first parameter.

3. When the formatting string ends or the read input does not match the type specified by the format string, the input is stopped.

4. In any case, the number of converted input values is returned as the return value of the function.

5. If the file has reached the end before any input value is converted, the function returns the constant value EOF.

Ii. printf family

1. the printf function family is used to create formatted output. This family has three functions: fprintf, printf, and sprintf.

2. Their prototype is as follows:

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

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

Int Sprint (char * buffer, char const * format ,...);

3. printf formats the values in the parameter list based on the format code and other characters in the format parameter.

4. Differences:

1> Use printf to output the output results to the standard output.

2> Use fprintf to use any output stream.

3> sprintf stores the result as a string ending with NUL to the specified buffer rather than writing the result to the stream.

The return values of these three functions are the actual number of printed or stored characters.

 

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.