Codeblocks中同时给整形数和字符型数组赋值,出现了一个诡异的情况

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/izhouxiaofei/article/details/51049247

 执行完scanf("%s", ch);这句的时候,n=3,已经赋好的值,直接变为n=0了,

把数组长度改变,就好了,(为 \0 保留了一个存储空间)

和C语言不一样,搞不懂为什么,是Codeblocks 中的一个bug 吗?

展开阅读全文

给结构体赋值诡异问题

04-12

我写了一个动态库,该动态库导出函数如下rn Decode(int nObject, unsigned char* pPacket, int nLength,CDMAParams *pParams)rn主程序通过传入CDMAParams *类型的结构体指针pParams来取值.rn结构体CDMAParams里面嵌套定义了一些结构体,类型定义如下:rntypedef struct theCDMAParamsrn rnint logcode;rnint SID;rnint PhoneStatus;rnfloat RxAGC;rnfloat TxAGC;rnfloat EcIo;rn...rnDAccessChannel dAccessChannel;rnDReverseChannelTraffic dReverseChannelTraffic;rnSYSTEMPARAM systemparam;rnSignalInfo signalInfo;rnACCESSPARAM accessParam;rnPowerControlParam powerControlParam;rnSnapshot snapShot;rnSMSInfo smsInfo;rnrnPilotSetCollection pilotSetsCollection;rnint T_COMP_HARD;rnfloat TxPower;rnint TxMode;rnint DSC;rnEVDORateParameters EVDORate;rnCDMAParams;rnrn...表示若干个结构体成员,sizeof(CDMAParams)的值为58040,rnDAccessChannel,DReverseChannelTraffic,SYSTEMPARAM等等都为结构体,rnrn其中PilotSetCollection定义如下rntypedef struct tagPilotSetCollectionrnrnint PILOT_INC;rnunsigned int nPilotCount;rnPilotSet pilotset[64];rn PilotSetCollection;rnrnEVDORateParameters定义如下:rntypedef struct tagEVDORateParametersrnrndouble EV_Rx_RLP_Thr;rndouble EV_Tx_RLP_Thr;rndouble EV_Rx_PktThr_Instant;rndouble EV_Rx_PktThr_Served;rndouble Rx_SU_Packet_thr;rndouble Rx_PktThr_Instant_SU;rndouble Rx_PktThr_Served_SU;rndouble Rx_SU_PER;rndouble Rx_PktThr_Instant_MU;rndouble Rx_PktThr_Served_MU;rnEVDORateParameters;rnrn我想调用动态库后取得PILOT_INC的值,但是总是为0,我调试跟踪进入动态库中后,发现PILOT_INC一直为非0值,rn但是一旦调用程序中Decode返回之后,PILOT_INC立即变为0,rn调试时发现,CDMAParams结构体中最后一个成员结构体EVDORateParameters EVDORate的值也没有正确拷贝过去,发生了32个字节的偏移,rnrnrn在给EVDORateParameters赋值后,在动态库内部运行时跟踪内存为:rnEV_Rx_RLP_Thr 0.000000000;rnEV_Tx_RLP_Thr 0.000000000;rnEV_Rx_PktThr_Instant 0.000000000;rnEV_Rx_PktThr_Served 0.000000000;rnRx_SU_Packet_thr [color=#FF0000]11197.440000001[/color];rnRx_PktThr_Instant_SU [color=#FF0000]12582.912000[/color];rnRx_PktThr_Served_SU [color=#FF0000]2313781.2789207213[/color];rnRx_SU_PER 0.000000000;rnRx_PktThr_Instant_MU 0.000000000;rnRx_PktThr_Served_MU 0.000000000;rn调用返回后,该结构体内存却变为:rnEV_Rx_RLP_Thr 0.000000000;rnEV_Tx_RLP_Thr 0.000000000;rnEV_Rx_PktThr_Instant 0.000000000;rnEV_Rx_PktThr_Served 0.000000000;rnRx_SU_Packet_thr 0.000000000;rnRx_PktThr_Instant_SU 0.000000000;rnRx_PktThr_Served_SU 0.000000000;rnRx_SU_PER 0.000000000;rnRx_PktThr_Instant_MU [color=#FF0000]11197.440000001[/color];rnRx_PktThr_Served_MU [color=#FF0000]12582.912000[/color];rn即本来三个非0值分别赋给Rx_SU_Packet_thr,Rx_PktThr_Instant_SU和Rx_PktThr_Served_SU的,rn但是却赋给了Rx_PktThr_Instant_MU和Rx_PktThr_Served_MU了,而2313781.2789207213干脆消失了,rn等于偏移了32个字节, 请高手们指点下原因.rn更诡异的事情是,当我将最后那几个成员移到结构体前面去以后(即将结构体定义换成下面这样),rn上述问题就不存在了,能正确取到值,rntypedef struct theCDMAParamsrn rnPilotSetCollection pilotSetsCollection;rnint T_COMP_HARD;rnfloat TxPower;rnint TxMode;rnint DSC;rnEVDORateParameters EVDORate;rnrnint logcode;rnint SID;rnint PhoneStatus;rnfloat RxAGC;rnfloat TxAGC;rnfloat EcIo;rn...rnDAccessChannel dAccessChannel;rnDReverseChannelTraffic dReverseChannelTraffic;rnSYSTEMPARAM systemparam;rnSignalInfo signalInfo;rnACCESSPARAM accessParam;rnPowerControlParam powerControlParam;rnSnapshot snapShot;rnSMSInfo smsInfo;rnCDMAParams;rnrn急!rnrn 论坛

同时查询时间型和字符

09-03

这是我调试后的结果:帐号='1111111111111111111'or 帐号='1111111111111111112'or 帐号='1234567891234567891'or 帐号='1111111111111111111'and 交易时间=2008-2-2 rn就是说对上面这语句进行setfilter()后报错,expression is not valid rn问题是:我对数值型和字符型一起查找时,是可以的.如上面把and 交易时间=2008-2-2替成数量等于20. rn我的目的是这样的,要把dw_3的窗口已经查询好的条件做为基础,然后再加个查询.并显示在dw_3上. rn注:我已经用过SQL的方法了,只是老报where附近出错.所以我就放弃了,用这种方法试试. rnrn下面是我目前的代码:______________________________________________________________________ rnif sle_2.text="" then rnmessagebox("注意!","请输入查找开始月份!") rnelse rn//定义参数:查条件综合结果 rnstring LookforCondition2,lookforcondition1,lookforcondition3,lookfrocondition4 rn//定义参数:要查询的列 rnstring LookforItem,lookforhow1,lookforhow2 rn//定义参数:要查询的内容 rnstring LookforWhat2,lookforwhat1 rn//定义参数:总的行数 rn int total_row rnstring all_col[] rnstring lookforallitem1,lookforallitem2 rnint i rntotal_row=dw_3.rowcount() rnif total_row=0 then rnmessagebox("注意","已经没有可查询数据!") rnelse rnfor i=1 to total_row rnall_col[i]=dw_3.getitemstring(i,1) rnnext rnlookforallitem2="编号"+"="+"'"+all_col[1]+"'" rni=2 rndo while i <=total_row rnlookforallitem1="编号"+"="+"'"+string(all_col[i])+"'" rnlookforallitem2=lookforallitem2+"or"+" "+lookforallitem1 rni=i+1 rnloop rnrn//查询子段和查询内容的选择 rnlookforcondition3="月份"+">="+""+string(lookforwhat1)+"" rnlookfrocondition4="月份"+" <="+""+string(lookforwhat2)+"" rnlookforcondition1=lookfrocondition4+"and"+" "+lookforcondition3 rnlookforCondition2=lookforallitem2+"and"+" "+lookforcondition1 rn//定义读者编号 rn//过滤数据窗口dw_1 rndw_3.setfilter(lookforCondition2) rnfilter(dw_3) 论坛

没有更多推荐了,返回首页