I have to prepare a string which has to be sent over socket, that string is constructed using different data types int, char, unsigned char etc... As i have used it in many places my callgrind report says most of the CPU consumed by sprintf and strcat.
Can some one tell me alternate for this sprintf and strcat idea?
Below is the piece of code
pData_temp = (char *)malloc(200);
pData = (char *)malloc(500);
sprintf(pData_temp, "String to be sent over socket at time %u $%04x",seconds,id);
strncpy(pData,pData_temp,strlen(pData_temp);
for in t(i=0; i < 1000; i++)
{
sprintf(pData_temp,"%02x%04x%08x%08x%08x",var1,var2,var3,var4,var5);
strcat(pData,pData_temp);
}
sprintf(pData_temp,"\n");
strcat(pData,pData_temp)
sock_send(pData,strlen(pData);
free(pData);
free(pData_temp);
Any help appriciated.
Regards