- 论坛徽章:
- 0
|
原帖由 loophole 于 2009-7-11 11:41 发表 ![]()
很多数据类型的宽度都记不住,用sizeof又不想些那几行,所以就构思一个小程序,通过argv[1]来确定数据类型,然后打印它。
./data int16
int16 2
象这样,小弟才疏学浅特此请教大虾们,用哪种算法实现好些 ...
#include <stdio.h>
#include <limits.h>
#include <float.h>
int
main () {
printf ("char %d bytes %d to %d \n", sizeof(char ), CHAR_MIN, CHAR_MAX );
printf ("unsigned char %d bytes %d to %d \n", sizeof(unsigned char ), 0 , UCHAR_MAX );
printf ("short %d bytes %hi to %hi \n", sizeof(short ), SHRT_MIN, SHRT_MAX );
printf ("unsigned short %d bytes %hu to %hu \n", sizeof(unsigned short), 0 , USHRT_MAX );
printf ("int %d bytes %i to %i \n", sizeof(int ), INT_MIN , INT_MAX );
printf ("unsigned int %d bytes %u to %u \n", sizeof(unsigned int ), 0 , UINT_MAX );
printf ("long %d bytes %li to %li \n", sizeof(long ), LONG_MIN, LONG_MAX );
printf ("unsigned long %d bytes %lu to %lu \n", sizeof(unsigned long ), 0 , ULONG_MAX );
printf ("float %d bytes %e to %e \n", sizeof(float ), FLT_MIN , FLT_MAX );
printf ("double %d bytes %e to %e \n", sizeof(double ), DBL_MIN , DBL_MAX );
printf ("precision of float %d digits\n", FLT_DIG);
printf ("precision of double %d digits\n", DBL_DIG);
return 0;
} |
来自网络 |
|