您好,我正在使用 xc8 compiler.sprintf 处理 Pic18f46k22 功能无法正常工作。我的代码是:
const char *DATA[4] = {"xxxxxx","yyyyyy","zzzzzz","aaaa"}
unsigned char Data1=2;
unsigned char Data2=3;
char L1Buffer[6];
char L2Buffer[6];
char TotalBuffer[20];
for(int i=0;i<6;i++){L1Buffer[i]=0;L2Buffer[i]=0;}
for(int i=0;i<20;i++){TotalBuffer[i]=0;}
sprintf (L1Buffer,"%s", DATA[Data1]);
sprintf (L2Buffer,"%s%d", DATA[Data2],Data2);
sprintf(TotalBuffer,"L1:%s L2:%s",L1Buffer,L2Buffer);
Lcd_Set_Cursor(2,1);
printf("%s",TotalBuffer);
Lcd_Set_Cursor(3,1);
printf("%s",L2Buffer);
输出 :
L1:zzzzzzaaaa3 L2:aa
aaaa3
预期输出:
L1:zzzzzz L2:aaaa3
aaaa3