C语言小程序 int数组写入字符串
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int len = 0;
int TestNum = 100;
int MaxLen = 1024;
char cMsgLog[MaxLen] = {0};
for(int i=0; i<TestNum; i++){
if(i < TestNum - 1 && MaxLen-len > 0){
len += snprintf(cMsgLog+len,MaxLen-len,"%d,",i);
}else if(MaxLen-len > 0){
len += snprintf(cMsgLog+len,MaxLen-len,"%d",i);
}
}
printf("log is %s.\n", cMsgLog);
}