The fscanf () function in C language and the vfscanf () function use the _c language

Source: Internet
Author: User

C language fscanf () function: Input function (more commonly used)
header file:

#include <stdio.h>

To define a function:

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

Function Description: fscanf () reads the string from the file stream in the parameter stream, and then converts and formats the data based on the parameter format string. Please refer to scanf () for the format conversion form. The converted structure is stored in the corresponding parameter.

Return value: Returns the number of parameters for success, failure returns 1, and the reason for the error is in errno.

Example

#include <stdio.h>
Main ()
{
  int i;
  unsigned int J;
  Char s[5];
  FSCANF (stdin, "%d%x%5[a-z]%*s%f", &i, &j, S, s);
  printf ("%d%d%s \ n", I, J, s);
}

Perform:

0x1b aaaaaaaaa bbbbbbbbbb//from keyboard input
AAAAA

C language vfscanf () function: Input function (format string before entering)
header file:

#include <stdio.h>

To define a function:

int vfscanf (FILE * stream, const char * format, va_list AP);

Function Description: VFSCANF () reads the string from the file stream in the parameter stream, and then converts and formats the data based on the parameter format string. Please refer to scanf () for the format conversion form. The converted results are stored in the corresponding parameters. Please refer to Appendix C or vprintf () for va_list usage.

Return value: Returns the number of parameters for success, failure returns 1, and the reason for the error is in errno.

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.