"%[^\n]"真的可以用scanf输入一个带空格的字符串吗?
确实可以!而且"%[^\n]"还可以由你自己选择结束字符。
这个%[]用的人不多,大家都只知道%s之类的,所以这个东西也被忽视了。。。
下面是MSDN的scanf格式参数的允许情况,注意%[]在最后呢~
Conversion Argument Conversion
Specifier Type Function Base
%c char x[]
%lc wchar_t x[]
%d int *x strtol 10
%hd short *x ...全部
确实可以!而且"%[^\n]"还可以由你自己选择结束字符。
这个%[]用的人不多,大家都只知道%s之类的,所以这个东西也被忽视了。。。
下面是MSDN的scanf格式参数的允许情况,注意%[]在最后呢~
Conversion Argument Conversion
Specifier Type Function Base
%c char x[]
%lc wchar_t x[]
%d int *x strtol 10
%hd short *x strtol 10
%ld long *x strtol 10
%e float *x strtod 10
%le double *x strtod 10
%Le long double *x strtod 10
%E float *x strtod 10
%lE double *x strtod 10
%LE long double *x strtod 10
%f float *x strtod 10
%lf double *x strtod 10
%Lf long double *x strtod 10
%g float *x strtod 10
%lg double *x strtod 10
%Lg long double *x strtod 10
%G float *x strtod 10
%lG double *x strtod 10
%LG long double *x strtod 10
%i int *x strtol 0
%hi short *x strtol 0
%li long *x strtol 0
%n int *x
%hn short *x
%ln long *x
%o unsigned int *x strtoul 8
%ho unsigned short *x strtoul 8
%lo unsigned long *x strtoul 8
%p void **x
%s char x[]
%ls wchar_t x[]
%u unsigned int *x strtoul 10
%hu unsigned short *x strtoul 10
%lu unsigned long *x strtoul 10
%x unsigned int *x strtoul 16
%hx unsigned short *x strtoul 16
%lx unsigned long *x strtoul 16
%X unsigned int *x strtoul 16
%hX unsigned short *x strtoul 16
%lX unsigned long *x strtoul 16
%[。
。。] char x[]
%l[。。。] wchar_t x[]
%% none。收起