关于在Keil c中使用sprintf函数的问题
KEILC程序如下:{...unsignedcharxdatastrbuf1[64];//打印字符串临时数组1unsignedcharxdatastrbuf2[64];/...
KEIL C 程序如下:
{
...
unsigned char xdata strbuf1[64]; //打印字符串临时数组1
unsigned char xdata strbuf2[64]; //打印字符串临时数组2
unsigned int xdata a_ADfz[9];
a_ADfz[0] = 0x8800 ;
a_ADfz[1] = 0x8800 ;
a_ADfz[2] = 0x8800 ;
a_ADfz[3] = 0x8800 ;
a_ADfz[4] = 0x8800 ;
a_ADfz[5] = 0x8800 ;
a_ADfz[6] = 0x8800 ;
a_ADfz[7] = 0x8800 ;
a_ADfz[8] = 0x8800 ;
SendCom1("\r\n");
SendCom1( "ADfz1:" );
sprintf(strbuf1,"%04X:%04X:%04X:", a_ADfz[0],a_ADfz[1],a_ADfz[2]);
SendCom1( strbuf1 );
sprintf(strbuf1,"%04X:%04X:%04X:", a_ADfz[3],a_ADfz[4],a_ADfz[5]);
SendCom1( strbuf1 );
sprintf(strbuf1,"%04X:%04X:%04X ", a_ADfz[6],a_ADfz[7],a_ADfz[8]);
SendCom1( strbuf1 );
SendCom1("\r\n");
SendCom1("\r\n");
sprintf(strbuf2,"ADfz2:%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X ", a_ADfz[0], a_ADfz[1],
a_ADfz[2], a_ADfz[3], a_ADfz[4], a_ADfz[5], a_ADfz[6], a_ADfz[7], a_ADfz[8] );
SendCom1( strbuf2 );
SendCom1("\r\n");
...
}
打印结果:
ADfz1:8800:8800:8800:8800:8800:8800:8800:8800:8800
ADfz2:8800:8800:8800:8800:880C:0400:0024:841F:9F00
问题:
为什么ADfz1和ADfz2的内容不一样? 展开
{
...
unsigned char xdata strbuf1[64]; //打印字符串临时数组1
unsigned char xdata strbuf2[64]; //打印字符串临时数组2
unsigned int xdata a_ADfz[9];
a_ADfz[0] = 0x8800 ;
a_ADfz[1] = 0x8800 ;
a_ADfz[2] = 0x8800 ;
a_ADfz[3] = 0x8800 ;
a_ADfz[4] = 0x8800 ;
a_ADfz[5] = 0x8800 ;
a_ADfz[6] = 0x8800 ;
a_ADfz[7] = 0x8800 ;
a_ADfz[8] = 0x8800 ;
SendCom1("\r\n");
SendCom1( "ADfz1:" );
sprintf(strbuf1,"%04X:%04X:%04X:", a_ADfz[0],a_ADfz[1],a_ADfz[2]);
SendCom1( strbuf1 );
sprintf(strbuf1,"%04X:%04X:%04X:", a_ADfz[3],a_ADfz[4],a_ADfz[5]);
SendCom1( strbuf1 );
sprintf(strbuf1,"%04X:%04X:%04X ", a_ADfz[6],a_ADfz[7],a_ADfz[8]);
SendCom1( strbuf1 );
SendCom1("\r\n");
SendCom1("\r\n");
sprintf(strbuf2,"ADfz2:%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X ", a_ADfz[0], a_ADfz[1],
a_ADfz[2], a_ADfz[3], a_ADfz[4], a_ADfz[5], a_ADfz[6], a_ADfz[7], a_ADfz[8] );
SendCom1( strbuf2 );
SendCom1("\r\n");
...
}
打印结果:
ADfz1:8800:8800:8800:8800:8800:8800:8800:8800:8800
ADfz2:8800:8800:8800:8800:880C:0400:0024:841F:9F00
问题:
为什么ADfz1和ADfz2的内容不一样? 展开
2个回答
展开全部
因为Keil采用的库函数是精简库,功能没有VC那么强大,具体到sprintf来说,字符串总长度不能超过15个字节,你第一种满足,第二种超了,其实还有些方面也没VC那么强
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
也许..是堆栈溢出了.
你可以单步调试..看一下你的sp到底跑到哪里去了
你可以单步调试..看一下你的sp到底跑到哪里去了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询