在strcat callc之间截获奇怪字符
我在CentOS6与C合作 当我使用strcat时,它会在字符串之间放置奇怪的字符,例如 ‘H’、‘p’、‘@’ 不幸的是,我无法显示我的完整来源,因为它是公司财产在strcat callc之间截获奇怪字符,c,char,append,strcat,C,Char,Append,Strcat,我在CentOS6与C合作 当我使用strcat时,它会在字符串之间放置奇怪的字符,例如 ‘H’、‘p’、‘@’ 不幸的是,我无法显示我的完整来源,因为它是公司财产 sprintf(tmp, "{\"vod\":{\"con_id\":\"%s\",\"thumbnails\":[", con_id); strcpy(json,tmp); char cmd[MAX]; char innerjson[MAX_JSON]; int t
sprintf(tmp, "{\"vod\":{\"con_id\":\"%s\",\"thumbnails\":[", con_id);
strcpy(json,tmp);
char cmd[MAX];
char innerjson[MAX_JSON];
int thumb_idx;
for(thumb_idx = 0; thumb_idx < thumb_cnt; thumb_idx++){
pos_second += interval;
sprintf(tmp,"{\"thumb_idx\":\"%d\", \"thumb_image\": \"thumbnail_%d.jpg\", \"position_t\":\"%d\"}", thumb_idx, thumb_idx, pos_second);
if(thumb_idx != thumb_cnt-1)
{
strcat(tmp, ", ");
strcat(innerjson, tmp);
}else
strcat(innerjson,tmp);
}
strcat(json, innerjson);
strcat(json,"]}}\n");
sprintf(tmp,“{\'vod\”:{\'con\u id\”:\%s\,“'thumbnails\”:[”,con\u id);
strcpy(json,tmp);
char cmd[MAX];
char innerjson[MAX_JSON];
int thumb_idx;
对于(thumb_idx=0;thumb_idx
每次我在JSP中打印json(变量)时。在缩略图之间有一个奇怪的字符(如上所述):[这里!{.
我认为“strcat(json,innerjson)”
部分有一些问题,但我找不到它。
其他部分都很好。缓冲区溢出、未定义的行为等。如何定义
json
?为什么不使用snprintf()
?检查temp和json的缓冲区大小buffers@H2CO3我将json定义为一个字符数组。它的长度是4096字节。我不知道snprintf。谢谢:D@555k我的其他字符数组的长度都是1024.tmp 1024,innerjson 2048,json 4096。。。