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”

原文地址:https://www.cnblogs.com/qiuchangyong/p/2920666.html