Part Number: TM4C129ENCPDT
Hi,
I am trying to run a function that is otherwise tested and work very well. However if I run the function on uController. The uController will hang on the sprintf statement.
This functions is actually combining two arrays such that one array is holding a string and another array is holding HEX characters. This function works very well if I simulate on my linux machine.
char Generate_Hostname(char *header, unsigned char *MacAddr, char *GeneratedHostName)
{
char hex_tmp[50];
unsigned char i;
strcpy(GeneratedHostName, header); //Copy Header of the hostname i.e. BECMS to GeneratedHostName
for (i = 0; i < 4; i++){sprintf(&hex_tmp[i*2],"%02x", *(MacAddr+i+2));} //Convert MacAddr numbers starting from MAC_Addr[2] upto MAC_Addr[5]
strcat(GeneratedHostName,hex_tmp);
return 1;
}
one can try by simply copying and pasting the following code to see quickly the function itself is working
#include<stdio.h>
#include<string.h>
#define HostNameHeader "TI_Device_"
char Generate_Hostname(char *header, unsigned char *MacAddr, char *hostname)
{
char hex_tmp[20];
unsigned char i;
strcpy(hostname, header);
for (i = 0; i < 4; i++){sprintf(&hex_tmp[i*2],"%02x", *(MacAddr+i+2));}
strcat(hostname,hex_tmp);
}
int main(void)
{
char hostname[50];
unsigned char MAC_Addr[6]={0xE0,0xC0,0x01,0x00,0xAF,0x60};
Generate_Hostname(HostNameHeader,&MAC_Addr[0],hostname);
printf("\n%s",hostname);
return 0;
}
.