F
Fernando Barsoba
Hi,
I'm using strtok() in the following way:
void obtain_param(char *pmsg, CONF_PARAMS *cnf ) {
char *s1, *s2;
size_t msg_len;
s1 = strtok (pmsg,":");
if (s1) {
s2 = strtok (0, "");
msg_len = strcspn(s2, "\n");
if (memcmp(s1, "message", sizeof("message")) == 0) {
cnf->msg_length = msg_len;
cnf->message = malloc(msg_len);
memcpy(cnf->message, s2, msg_len);
cnf->message[msg_len]='\0';
....
I extract the information from a configuration file. For some reason,
sometimes I get for msg_len 15 for this message:
(when 'this is a test\n' is only 14 characters long, w/o the '\n')
In other installations (Linux) works just fine, but in my
Eclipse/CDT/cygwin sometimes is not.
Am I using strtok incorrectly? is the 's2' pointer messing things up?
Thanks,
F~
I'm using strtok() in the following way:
void obtain_param(char *pmsg, CONF_PARAMS *cnf ) {
char *s1, *s2;
size_t msg_len;
s1 = strtok (pmsg,":");
if (s1) {
s2 = strtok (0, "");
msg_len = strcspn(s2, "\n");
if (memcmp(s1, "message", sizeof("message")) == 0) {
cnf->msg_length = msg_len;
cnf->message = malloc(msg_len);
memcpy(cnf->message, s2, msg_len);
cnf->message[msg_len]='\0';
....
I extract the information from a configuration file. For some reason,
sometimes I get for msg_len 15 for this message:
(when 'this is a test\n' is only 14 characters long, w/o the '\n')
In other installations (Linux) works just fine, but in my
Eclipse/CDT/cygwin sometimes is not.
Am I using strtok incorrectly? is the 's2' pointer messing things up?
Thanks,
F~