Re: strtok() and EOL



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,":");
(...)
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"

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:

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~
.



Relevant Pages

  • Re: How to print a file in binary mode
    ... well, if I just open the file in binary mode, and write a string,e.g ... > so I first convert the string to binary,and then saving the binary ... you get an 8-bit string that contains the binary data. ... print the picture by binary! ...
    (comp.lang.python)
  • Re: [C++] Rewinding an isteam and GNU G++
    ... Try to open the stream in binary mode ... char Char(0); ... You will find that opening the file in binary mode, ... If using Windows for example, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: [C++] Rewinding an isteam and GNU G++
    ... Try to open the stream in binary mode ... char Char(0); ... You will find that opening the file in binary mode, ... If using Windows for example, ...
    (comp.lang.cpp)
  • Re: Reading from a Serial Port Part II
    ... No other routine is required. ... the string value of the binary? ... just fine and can receive data fine in text mode but not in binary mode. ... Private Sub Form1_Load(ByVal sender As System.Object, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: strtok() and EOL
    ... the string I'm getting is "message:this is a test\r\n". ... And 'pmsg' comes also from a file. ... I'm not opening the file in binary mode though.. ... emulation Unix to a degree so by default it used the Unix text file conventions. ...
    (comp.lang.c)