Re: stripping newline from input
On Fri, 03 Sep 2004 14:40:27 +0000, Dan Pop wrote:
[color=blue]
> In <pan.2004.09.02 .01.49.53.37717 @bar.net> Mac <foo@bar.net> writes:
>[color=green]
>>On Wed, 01 Sep 2004 13:42:01 +0000, Dan Pop wrote:
>>[snip]
>>[color=darkred]
>>> You mean you have used a plain "r" in your fopen call and ended up with
>>> input lines terminated in \r\n ? In this case, your C programming
>>> environment is hopelessly broken.
>>>[/color]
>>
>>Well, either that or he somehow created a Windows style text file on a
>>unix style machine, either by editing it with a windows (or DOS)
>>application via samba or NFS or something, or by extracting from an
>>archive of some sort without performing the correct conversion.
>>
>>If that is the case, then technically it is not a text file on the
>>platform where he is reading it, I guess. So there might not necessarily
>>be anything wrong with the C programming environment.
>>
>>This happens often enough that it is worthwhile to deal with it
>>intelligently , in my opinion.[/color]
>
> In my, admitedly, limited experience, Windows implementations return \n
> when encountering a \n character in the input file. The missing \r
> doesn't make any difference.
>
> Dan[/color]
I don't know anything to the contrary, although I have noticed that some
(maybe all?) versions of notepad don't handle \n only lines very well.
Wordpad does handle these lines just fine, though.
The case I was thinking of was when you read a windows text file in unix
land. If you are parsing the file, you should deal with the \r gracefully,
somehow. I think it should be safe to just ignore it, in this case.
--Mac
On Fri, 03 Sep 2004 14:40:27 +0000, Dan Pop wrote:
[color=blue]
> In <pan.2004.09.02 .01.49.53.37717 @bar.net> Mac <foo@bar.net> writes:
>[color=green]
>>On Wed, 01 Sep 2004 13:42:01 +0000, Dan Pop wrote:
>>[snip]
>>[color=darkred]
>>> You mean you have used a plain "r" in your fopen call and ended up with
>>> input lines terminated in \r\n ? In this case, your C programming
>>> environment is hopelessly broken.
>>>[/color]
>>
>>Well, either that or he somehow created a Windows style text file on a
>>unix style machine, either by editing it with a windows (or DOS)
>>application via samba or NFS or something, or by extracting from an
>>archive of some sort without performing the correct conversion.
>>
>>If that is the case, then technically it is not a text file on the
>>platform where he is reading it, I guess. So there might not necessarily
>>be anything wrong with the C programming environment.
>>
>>This happens often enough that it is worthwhile to deal with it
>>intelligently , in my opinion.[/color]
>
> In my, admitedly, limited experience, Windows implementations return \n
> when encountering a \n character in the input file. The missing \r
> doesn't make any difference.
>
> Dan[/color]
I don't know anything to the contrary, although I have noticed that some
(maybe all?) versions of notepad don't handle \n only lines very well.
Wordpad does handle these lines just fine, though.
The case I was thinking of was when you read a windows text file in unix
land. If you are parsing the file, you should deal with the \r gracefully,
somehow. I think it should be safe to just ignore it, in this case.
--Mac
Comment