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:

<snip>

 >>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"

Note that since Cygwin is emulating some of Unix it may think of \n as being the line terminator rather than \r\n even when you open a stream in text mode, so you could still get a spurious \r. For the intricacies of Cygwin line termination you will have to ask on a Cygwin mailing list, but if this is your problem one option is to check if the last character of the line you read is \r and if so strip it.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.




Relevant Pages

  • Re: csv.Sniffer: wrong detection of the end of line delimiter
    ... Laurent Laporte wrote: ... The file is opened in binary mode, so I keep the end of line terminator. ... It's not advisable to open a file like a CSV, intended for use as text, in binary mode. ...
    (comp.lang.python)
  • Re: append one file to another
    ... > the code needs to run under Windows or cross-platform. ... and possibly the end-of-file marker. ... danged file in binary mode and you can't go wrong. ... but I've never had any problems using 'rb' for text files under Linux. ...
    (comp.lang.python)
  • Re: Terminator Character
    ... the Matlab output requires this terminator character to be CR/LF. ... Can somebody tell me how to change the default setting of the terminator ... You can open the file in binary mode: ... The fprintf command was simply being used to write a string to a text file, and that text file would then be read and executed by a .NET program. ...
    (comp.soft-sys.matlab)
  • Re: FTP Offset larger than file.
    ... That fix works seamlessly in Linux, ... the same error in a Windows environment. ... Consider opening the file in binary mode, by passing the 'wb' and 'ab' ...
    (comp.lang.python)
  • Re: Terminator Character
    ... the Matlab output requires this terminator character to be CR/LF. ... Can somebody tell me how to change the default setting of the terminator ... You can open the file in binary mode: ...
    (comp.soft-sys.matlab)