Works for me.
Code:
#include<stdio.h>
#include<string.h>
#define MESSAGE_MAX_LENGTH 100
#define MESSAGE_ID_MAXLEN 10
#define MSG_DELIMITER ","
typedef struct Initial_parse {
char talker_ID[7];
char message_ID[MESSAGE_ID_MAXLEN];
char * data_field;
int checksum;
} Initial_parse;
void parse_initial_message (const char * message, Initial_parse *ip)
{
char temp_str[MESSAGE_MAX_LENGTH];
char * temp_talker_ID;
strcpy(temp_str, message); //we stored the message in temporary copy
temp_talker_ID = strtok(temp_str, MSG_DELIMITER);
strcpy(ip->talker_ID, temp_talker_ID);
return;
}
int main ( ) {
Initial_parse ip;
parse_initial_message("hello,world",&ip);
printf("%s\n",ip.talker_ID);
}
Obviously, you've screwed up the memory somewhere else in the code.
What you posted is where the problem shows up, not where the problem was caused.
Maybe you call it with a string which is too long, or is missing the delimiter.