实现基本数据类型字节统计

来源:百度知道 编辑:UC知道 时间:2024/05/24 15:47:18
功能:实现基本数据类型字节统计
目前支持的类型:short int long float double
例子:输入int后输出4
注意:分析每个类型不同,从用户的角度出发考虑问题,考虑用户使用的友好性。

#include<stdio.h>
#include<string.h>
main()
{
char s[10];
while(1)
{
printf("Input the type of variable or 'exit' to break。\n");
scanf("%s",s);
if(strcmp("short",s)==0)
printf("the size of %s is %d\n",s,sizeof(short));
else if(strcmp("int",s)==0)
printf("the size of %s is %d\n",s,sizeof(int));
else if(strcmp("long",s)==0)
printf("the size of %s is %d\n",s,sizeof(long));
else if(strcmp("float",s)==0)
printf("the size of %s is %d\n",s,sizeof(float));
else if(strcmp("double",s)==0)
printf("the size of %s is %d\n",s,sizeof(double));
else if(strcmp("exit",s)==0)
exit(1);
else
printf("Illegal input!\n");
}
}