On Tue, 29 Nov 2005 15:16:17 GMT, Fernando Barsoba
<> wrote in comp.lang.c:
> 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:
>
> >>message:this is a test
>
> (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~
Where did the text string passed in 'pmsg' come from? Was it read
from a file? If it was read from a file, was the file opened in text
or binary mode? If you are reading a text file opened in binary mode
under Windows, you are getting the string as it appears in the file,
which would be:
"message:this is a test\r\n"
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html