我在连接字符串时遇到问题。我认为这是个愚蠢的问题,但我没有得到答案。这就是我在这里发帖的原因。请帮助我。
源代码是
unsigned char arr_25[] = "{\"category\":\"",
arr_10[]="FMCG",
arr_26[]="\"amount\":",
arr_11[]="\",",
arr_12[]="1000",
arr_13[]="}";
float amount=1500,totamount=2500;
for(i=0;i<=count;i++)
{
if(i>0)
strcat(buff,",");
strcat(buff,arr_25);
strcat(buff,arr_10);//I am getting unnecessary value while printing this arr_10
strcat(buff,arr_11);
strcat(buff,arr_26);
memset(arr_12,0,sizeof(arr_12));
sprintf(arr_12,"%.2f",amount);
printf("\n the amount is %s \n",arr_12);
strcat(buff,arr_12);
strcat(buff,arr_13);
}
打印我得到的buff值后
{"category":"FMCG","amount":1500.00},{"category":"FMCG00"amount":1500.00},{"category":"FMCG00"amount":1500.00},{"category":"FMCG00"amount":1500.00}
我正进入(状态:"FMCG,FMCG00,FMCG00..."
为什么会出现这种情况?当我将 arr-10 值硬编码到 FMCG 时..?
提前致谢....