zoukankan      html  css  js  c++  java
  • scanf的使用要注意

    下面是CSDN里对scanf的使用的例子。

    // crt_scanf.c
     /* This program uses the scanf and wscanf functions
      * to read formatted input.
      */

    #include <stdio.h>

    int main( void )
    {
       int   i, result;
       float fp;
       char  c, s[81];
       wchar_t wc, ws[81];
       result = scanf( "%d %f %c %C %80s %80S", &i, &fp, &c, &wc, s, ws );
       printf( "The number of fields input is %d\n", result );
       printf( "The contents are: %d %f %c %C %s %S\n", i, fp, c, wc, s, ws);
       result = wscanf( L"%d %f %hc %lc %80S %80ls", &i, &fp, &c, &wc, s, ws );
       wprintf( L"The number of fields input is %d\n", result );
       wprintf( L"The contents are: %d %f %C %c %hs %s\n", i, fp, c, wc, s, ws);
    }

    我需要补充一下,如果输入接受的是一个float,用"%f";如果输入接受的是一个double,要用"%lf”

  • 相关阅读:
    10月27号
    10月23号
    10月26号
    10月30号
    10月28号
    10月29号
    JAVA日报
    JAVA日报
    JAVA日报
    JAVA日报
  • 原文地址:https://www.cnblogs.com/qiuchangyong/p/2920666.html
Copyright © 2011-2022 走看看