I have been trying to get a program that someone else wrote to work on my Ubuntu computer. The following string was defined as
char msg[256];
Then the following function was built
Code:
void
sprt_hex(char *line, unsigned char *frame, time_t *sys_time, time_t *clock_time)
{
char hex_str[3];
int i, len;
len = datalen[(int) frame[0]];
// printf("%ld\n", *sys_time); //debug line
// printf("%ld\n", *clock_time); //debug line
sprintf(line, "%ld %ld", *sys_time, *clock_time);
// printf("%s\n",line);
for (i = 0; i < len; i++)
{
sprintf(hex_str," %x", frame[i]);
// printf("%x ", frame[i]);
strcat(line, hex_str);
}
strcat(line,"\n");
//debug
// printf("\n");
printf("Line %s", line);[/B]
// printf("%02d\n",strlen(line));
//debug end
}
This function was called with....with debugging statements printf...
Code:
sprt_hex(msg, frame, &sys_time, &clock_time);
printf("MSG after %s\n", msg);
printf("string length %03d\n", strlen(msg));
Program output is ...
Line 1193795307 1193792367 3 21 37 0 82 1
MSG after �f
string length 004
The function call to sprt_hex should send the pointer of msg to the function. The char *line is built properly. The value of line should populate that pointer location for msg, but instead I am passing jibberish.
Help please!