What type does the sscanf Modifier

前端 未结 3 994
夕颜
夕颜 2021-01-25 17:22

I have come across some legacy code that has the following type of line:

sscanf(szBuff,\"%Fd %Ff %Fd %Ff\"

Has anyone seeen a modifier like Fd or Ff? If so, wha

相关标签:
3条回答
  • 2021-01-25 17:50

    As ouah pointed out, these are the same as their lower case counterparts. Why is that? For symmetry with the printf conversion specifiers. Here %x and %X write lowercase or uppercase numbers like deadbeef and DEADBEEF. The symmetry allows to use the same format string for both input with scanf and output with printf.

    #define FMT "%F\n"
    
    sscanf (str, FMT, &value);
    printf (FMT, value);
    
    0 讨论(0)
  • 2021-01-25 18:01

    %F is a POSIX (and C99) extension.

    http://pubs.opengroup.org/onlinepubs/007904975/functions/scanf.html

    "The conversion specifiers A, E, F, G, and X are also valid and shall be equivalent to a, e, f, g, and x, respectively."

    0 讨论(0)
  • 2021-01-25 18:08

    C says for fscanf functions:

    (C991, 7.19.6.2p14) The conversion specifiers A, E, F, G, and X are also valid and behave the same as, respectively, a, e, f, g, and x.

    So in %Fd, the conversion specification is %F which is equivalent to %f. Note that the d is not part of the conversion specification.

    For example (for fprintf functions %F is also the same as %f):

    printf("%fd\n", 3.141592);
    

    will print:

    3.141592d
    


    1. C89/C90 does not recognize the F conversion specifier. For example, for fscanf the corresponding C90 paragraph in 7.9.6.2 says: The conversion specifiers E, G, and X are also valid and behave the same as, respectively e, g, and x

    0 讨论(0)
提交回复
热议问题