Re: strtok() and EOL
- From: Fernando Barsoba <fbarsoba@xxxxxxxxxxx>
- Date: Tue, 29 Nov 2005 19:16:17 GMT
Jack Klein wrote:
(...)On Tue, 29 Nov 2005 15:16:17 GMT, Fernando Barsoba <fbarsoba@xxxxxxxxxxx> 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,":");
Thanks to all for your comments. Indeed, the string I'm getting is "message:this is a test\r\n". And 'pmsg' comes also from a file. Oddly enough, I thought I opened the file in text mode. Here's the sequence of calls: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"
fp = open_file(argv[1], "r"); cnf = get_param(fp);
-------------
CONF_PARAMS *get_param(FILE *f_param) {
....
p_msg = fgets(param, PARAM_LENGTH, f_param);
....
}
--------
FILE * open_file(char *file_name, char *foptions) {
FILE *fp;
if ((fp = fopen(file_name, foptions)) == NULL) {
printf("Can't open %s\n", file_name);
exit(1);
}
return fp;
}As the comments pointed out, this seems to be a Windows issue. That's why in Linux works fine. I'm not opening the file in binary mode though..
F~ .
- Follow-Ups:
- Re: strtok() and EOL
- From: Flash Gordon
- Re: strtok() and EOL
- References:
- strtok() and EOL
- From: Fernando Barsoba
- Re: strtok() and EOL
- From: Jack Klein
- strtok() and EOL
- Prev by Date: Re: direct string manuplation not working
- Next by Date: Re: C function for returning number of digits?
- Previous by thread: Re: strtok() and EOL
- Next by thread: Re: strtok() and EOL
- Index(es):
Relevant Pages
|