实在是想不出来为什么了,求解!!!!
程序代码:
#include <stdio.h> #include <stdlib.h> void printf_lxheshu(char lx,char shu); void zhuanhuanhanshu_i(int lxz,long zhuanhuan,long zhuanhuanhou); void zhuanhuanhanshu_f(int lxz,long zhuanhuan,long zhuanhuanhou); void yichu_i(long zhuanhuan,long zhuanhuanhou); void yichu_f(long double zhuanhuan,long double zhuanhuanhou); int main (void) { unsigned char lx[40],shu[40]; int lxz; printf("请输入你要求的类型(有short,int,long,float,double,longdouble):\n"); scanf("%s",lx); printf("请输入你要求的数\n"); scanf("%s",shu); printf("您输入的数的类型是%s,",lx); printf("您输入的数是%s,",shu); lxz =(int)lx[0]+(int)lx[1]+(int)lx[2]+(int)lx[3]+(int)lx[4]+(int)lx[5]; if(atof(shu)!=atol(shu)) { long double zhuanhuan,zhuanhuanhou; zhuanhuan = atof(shu); zhuanhuanhanshu_f(lxz,zhuanhuan,zhuanhuanhou); yichu_f(zhuanhuan,zhuanhuanhou); } if(atof(shu)==atol(shu)) { long zhuanhuan,zhuanhuanhou; zhuanhuan = atol(shu); zhuanhuanhanshu_i(lxz,zhuanhuan,zhuanhuanhou); yichu_i(zhuanhuan,zhuanhuanhou); } } void zhuanhuanhanshu_i(int lxz,long zhuanhuan ,long zhuanhuanhou) { if (lxz==560) zhuanhuanhou=(short)zhuanhuan; if (lxz==739) zhuanhuanhou=(int)zhuanhuan; if (lxz==651) zhuanhuanhou=(long)zhuanhuan; } void zhuanhuanhanshu_f(int lxz,long zhuanhuan, long zhuanhuanhou) { if (lxz==643) zhuanhuanhou=(long double)zhuanhuan; if (lxz==635) zhuanhuanhou=(double)zhuanhuan; if (lxz==534) zhuanhuanhou=(float)zhuanhuan; } void yichu_i(long zhuanhuan,long zhuanhuanhou) { if(zhuanhuan==zhuanhuanhou) printf("未溢出"); if(zhuanhuan!=zhuanhuanhou) printf("溢出,转换后的数为%d",zhuanhuanhou); } void yichu_f(long double zhuanhuan,long double zhuanhuanhou) { if( zhuanhuan==zhuanhuanhou) printf("未溢出"); if (zhuanhuan!=zhuanhuanhou) printf("溢出,得到数为%f",zhuanhuanhou); }
zhuanhuanhou=(short)zhuanhuan;
if (lxz==739)
printf("%d",zhuanhuanhou);
zhuanhuanhou=(int)zhuanhuan;
if (lxz==651)
zhuanhuanhou=(long)zhuanhuan; 在这里加printf函数,显示 zhuanhuanhou 的值为3,是正常的
long zhuanhuan,zhuanhuanhou;
zhuanhuan = atol(shu);
zhuanhuanhanshu_i(lxz,zhuanhuan,zhuanhuanhou);
printf("%d",zhuanhuanhou);
yichu_i(zhuanhuan,zhuanhuanhou); 在这里加printf函数就变成-858993460
我实在是想不通为什么在自定义的函数里 是对的,一出来就错了呢,郁闷死了,求大神教我啊~~~~~~~~~~~~~~~
30分啊~~~我的全部积蓄了,来人拿啊
[ 本帖最后由 hutianlun 于 2013-7-13 03:49 编辑 ]