Twelve, formatted I / O

1、fprintf

Header files #include <stdio.h>

Defined function int fprintf (FILE * stream, const char * format, .......);

Function Description fprintf () will be converted and formatted according to a parameter string format data, and then outputs the result to parameter stream file specified, up until the end of the string appears ( '\ 0').

Return value parameter regarding the format string format refer to printf (). The actual output successful returns the number of characters, failure -1 is returned, the cause of the error is stored in errno.

2、fscanf

Header files #include <stdio.h>

Defined function int fscanf (FILE * stream, const char * format, ....);

Function Description the fscanf () reads a file from the string parameter stream in the stream, and then converts the data format according to the parameter string format.

      Refer to the form of format conversion scanf (). Structure after conversion stored in the corresponding parameter.

Return Value Returns the number of parameters success, -1 on failure, the cause of the error stored in errno.

3、printf

Header files #include <stdio.h>

Defined function int printf (const char * format, .............);

Function Description fprintf () will be converted and formatted according to a parameter string format data, and then outputs the result to parameter stream file specified, up until the end of the string appears ( '\ 0').

Return value parameter regarding the format string format refer to printf (). The actual output successful returns the number of characters, failure -1 is returned, the cause of the error is stored in errno.

1、fprintf

Header files #include <stdio.h>

Defined function int fprintf (FILE * stream, const char * format, .......);

Function Description printf () format can be converted according to the parameters and formats the data string, and then write the result to the standard output device, up until the end of the string appears ( '\ 0'). Format string parameter may comprise the following three types of characters:

      1. General texts, with direct output.

      2.ASCII control characters, such as \ t, \ n the like.

      3. The format conversion character.

      Format to a format character percent sign (%), and after the composition. In general, each symbol% ​​are thereafter must have a printf () parameter with echoes (%% conversion only when the character appears directly output characters%), and wish to have the type of data output corresponding thereto the same character type conversion.

      printf general form format conversion () as follows:

      %〔flags〕〔width〕〔.prec〕type

      In the brackets to selectively parameter arguments, and type and% are necessary. Beneath introduce several forms of type:

      Integer:

      % D parameter will be converted to an integer of a signed decimal number

      Parameters% u is an integer unsigned converted into a decimal number

      Parameters% o is an integer unsigned converted into a digital octal

      Parameters% x is an integer unsigned converted into a hexadecimal number, and in lower abcdef

      Parameters% X is an integer unsigned converted into a hexadecimal number, and in uppercase ABCDEF

      Floating-point number:

      % F double type parameters are converted into decimal numbers and accessible to six decimal rounded.

      % E double type parameters of the printing exponentially, there will be a number before the decimal point, six digits after the decimal point, while the exponent portion e can be represented in lowercase.

      % E% e with the same effect, the only difference is the exponential part E uppercase will be represented.

      % G double type, parameters are automatically selected to% f% e or print format, which is determined according to the standard value of significant digits to be printed and provided.

      % G% G with the same effect, the only difference when the index print to form will choose% E format.

      Character and string:

      % Of the integer parameter c is converted to an unsigned char printed out.

      % S point parameter string is output verbatim, up until the NULL character appears

      If the parameter is% p "void *" type pointer is displayed in hexadecimal format.

      prec There are several situations:

      1. The minimum number of digits of a positive integer.

      2. The representative of decimal digits in floating-point numbers

      3. representative of the maximum number of significant digits in the format% g.

      4. The maximum length of the string representing the format of% s.

      5. If it is a symbol × represents the maximum length of the parameter value.

      width minimum length parameter, if this value is not a column, but the * symbol indicates the length parameter as a parameter.

      flags are the following situations:

      - This flag value will be a left-aligned.

      + Generally negative during printing, the printf () will be a negative number imprinted, not add any negative integer. This flag will be a positive number such that the plurality before printing positive (+).

      # This flag will have different meanings depending on the subsequent conversion of characters. When prior to (e.g.,% # o) type o, a o will print more octal values ​​before printing.

      In the prior type x (% # x) before printing will print more hexadecimal '0x', the type is e, will be forced to print decimal value before E, f, g, or G.

      While retaining the end of decimal digits and the decimal point in the time or type of G before the zero g.

      0 When the specified parameters, no parameters will make the digital 0. This flag is off by default, so the general will print out blank characters.

Return Value Returns Success actual output number of characters, -1 on failure, the cause of the error stored in errno.

4、scanf

Header files #include <stdio.h>

Defined function int scanf (const char * format, .......);

Description function scanf () to convert the input data and will format the data according to the parameter string format. scanf general form format conversion () as follows:

      % [*] [Size] [ l] [h] type
      in brackets in the parameter to selectively parameters, and type and% are necessary.
      * Represents the corresponding parameter data saved ignored.
      to allow the size of the data length of the input parameters.
      Data stored in the input value of l or double type long int.
      h value data input to save short int type.
      Type described under several forms:
      the data% d input will be converted to a signed decimal number (int).
      % I input data will be converted to a signed decimal number, if the input data is
      "0x" representative of the beginning or "0X" conversion of hexadecimal digits, if the beginning of the "0" then go to
      change octal number, otherwise It represents the decimal.
      0% input data is converted into an unsigned octal number.
      % U of the input data is converted to an unsigned integer.
      Data input% x unsigned hexadecimal number, stored in the converted unsigned int
      type variables.
      % X% X with the
      data input for the% f signed floating-point number after the conversion is stored in a float variables.
      With F% e%
      % with E F%
      % G with F%
      % S as input data to a space character string of the termination.
      % C input data into a single character.
      [] But only read the data characters in parentheses allowed. The [az].
      [^] But not the character data read in parentheses after the caret appears as [^ 0-9].

Return Value Returns the number of parameters success, -1 on failure, the cause of the error stored in errno.

5、sprintf

Header files #include <stdio.h>

Defined function int sprintf (char * str, const char * format, .........);

Function Description sprintf () will be converted and formatted according to a parameter string format data, and copies the result to the parameter string array referred str, up until the end character string appears ( '\ 0'). About the format parameter string format, please refer to printf ().

Return value parameters for the length of the string str returns, -1 on failure, the cause of the error stored in errno.

Description Use this function to obtain additional note stack overflow, or use snprintf ().

6、sscanf 

Header files #include <stdio.h>

Defined function int sscanf (const char * str, const char * format, ........);

Function Description sscanf () will str parameter string format and converts the data according to the parameter string format. Refer to the form of format conversion scanf (). Converted result stored in the corresponding parameter.

Return Value Returns the number of parameters success, -1 on failure, the cause of the error stored in errno.

7、vfprintf

Header files #include <stdio.h>

      #include<stdarg.h>

Defined function int vfprintf (FILE * stream, const char * format, va_list ap);

Function Description vfprintf () will be converted and formatted according to a parameter string format data, and then outputs the result to parameter stream file specified, up until the end of the string appears ( '\ 0').

      About the format parameter string format, please refer to printf (). Refer to Appendix C va_list usage or vprintf () paradigm.

Return Value Returns Success actual output number of characters, -1 on failure, the cause of the error stored in errno.

8、vfscanf

Header files #include <stdio.h>

Defined function int vfscanf (FILE * stream, const char * format, va_list ap);

The vfscanf Description Function () reads a file from the string parameter stream in the stream, and then converts the data format according to the parameter string format. Refer to the form of format conversion scanf (). Converted result stored in the corresponding parameter. Refer to Appendix C va_list usage or vprintf ().

Return Value Returns the number of parameters success, -1 on failure, the cause of the error stored in errno.

9, vprintf

Header files #include <stdio.h>

      #include<stdarg.h>

Defined functions int vprintf (const char * format, va_list ap);

Function Description vprintf, () action and printf () the same, the format is the same format parameter. va_list variable as a parameter the number of columns, usage and examples, please refer to Appendix C.

Return Value Returns Success actual output number of characters, -1 on failure, the cause of the error stored in errno.

10、vscanf

Header files #include <stdio.h>

      #include<stdarg.h>

Defined function int vscanf (const char * format, va_list ap);

Function Description vscanf () to convert the input data and will format the data according to the parameter string format. Refer to the form of format conversion scanf (). Converted result stored in the corresponding parameter. Refer to Appendix C va_list usage or vprintf () paradigm.

Return Value Returns the number of parameters success, -1 on failure, the cause of the error stored in errno.

11、vsprintf

Header files #include <stdio.h>

Defined function int vsprintf (char * str, const char * format, va_list ap);

Function Description vsprintf () will be converted and formatted according to a parameter string format data, and copies the result to the parameter string array referred str, up until the end character string appears ( '\ 0'). About the format parameter string format, please refer to printf (). Refer to Appendix C va_list usage or vprintf () paradigm.

Return value parameters for the length of the string str returns, -1 on failure, the cause of the error stored in errno.

12、vsscanf

Header files #include <stdio.h>

Defined function int vsscanf (const char * str, const char * format, va_list ap);

The vsscanf Description Function () will str parameter string format and converts the data according to the parameter string format. Format conversion form or vprintf, see Appendix C () paradigm.

Return Value Returns the number of parameters success, -1 on failure, the cause of the error stored in errno.

Guess you like

Origin www.cnblogs.com/Malphite/p/11427301.html