fgetl() on Windows

View: New views
7 Messages — Rating Filter:   Alert me  

fgetl() on Windows

by AlexG1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I'm having some trouble using the fgetl() function on a Windows system.
Every line in a Windows file ends with <cr><lf>. While fgetl() ignores the <lf> character it doesn't ignore <cr> (unlike the Matlab version of the same function), which can be problematic in some cases (e.g. when I'm reading a file path and then try to use fopen() on it - I get fid = -1).

Is there a function which ignores <cr> completely, or should I shorten every line that is read by 1 character?

Thanks,

Alex

fgetl() on Windows

by John W. Eaton-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 11-May-2009, AlexG1 wrote:

| I'm having some trouble using the fgetl() function on a Windows system.
| Every line in a Windows file ends with <cr><lf>. While fgetl() ignores the
| <lf> character it doesn't ignore <cr> (unlike the Matlab version of the same
| function), which can be problematic in some cases (e.g. when I'm reading a
| file path and then try to use fopen() on it - I get fid = -1).
|
| Is there a function which ignores <cr> completely, or should I shorten every
| line that is read by 1 character?

What version of Octave?  As I recall, this problem was fixed some time
ago.  It seems to work correctly for me wiht 3.0.5 on a Debian system
reading files with CRLF line endings.

jwe
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: fgetl() on Windows

by Bobatapl :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Alex,

You can get rid of the <cr> at the end of the line using:

dos2unix file.in file.out

If you don't have access to a Unix or Linux system, there may be a
Windows version of that function.  If you know anyone with a Linux or
Unix system they will have the proper function and can easily do it for
you.

Also there is a complementary function: unix2dos which adds the <cr> and
linefeed to the end of every line.

Bob


On Mon, 11 May 2009, AlexG1 wrote:

>
> Hello,
>
> I'm having some trouble using the fgetl() function on a Windows system.
> Every line in a Windows file ends with <cr><lf>. While fgetl() ignores the
> <lf> character it doesn't ignore <cr> (unlike the Matlab version of the same
> function), which can be problematic in some cases (e.g. when I'm reading a
> file path and then try to use fopen() on it - I get fid = -1).
>
> Is there a function which ignores <cr> completely, or should I shorten every
> line that is read by 1 character?
>
> Thanks,
>
> Alex
> --
> View this message in context: http://www.nabble.com/fgetl%28%29-on-Windows-tp23483929p23483929.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> Help-octave@...
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: fgetl() on Windows

by AlexG1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


John W. Eaton-3 wrote:
On 11-May-2009, AlexG1 wrote:



What version of Octave?  As I recall, this problem was fixed some time
ago.  It seems to work correctly for me wiht 3.0.5 on a Debian system
reading files with CRLF line endings.

jwe
Version 3.0.1

Re: fgetl() on Windows

by AlexG1 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Bobatapl wrote:
Hi Alex,

You can get rid of the <cr> at the end of the line using:

dos2unix file.in file.out

If you don't have access to a Unix or Linux system, there may be a
Windows version of that function.  If you know anyone with a Linux or
Unix system they will have the proper function and can easily do it for
you.

Also there is a complementary function: unix2dos which adds the <cr> and
linefeed to the end of every line.

Bob
Hmm, no such function on the Windows version.
Letting someone do it manually for every file isn't practical since this script might be used quite often and not only by myself.

For now I solved the problem by using strtrim() on the string returned by fgetl(), apparently it removes the <cr> tag.

Re: fgetl() on Windows

by Bobatapl :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Alex,

Here is a GPL version of dos2unix/unix2dos that will run on Windows. You
can call this from inside your octave script with the 'system' function
in octave. I think this will do what you need.

http://users.erols.com/dnagle/pub/d2u.c

Bob


On Mon, 11 May 2009, Bob Odom wrote:

> Hi Alex,
>
> You can get rid of the <cr> at the end of the line using:
>
> dos2unix file.in file.out
>
> If you don't have access to a Unix or Linux system, there may be a
> Windows version of that function.  If you know anyone with a Linux or
> Unix system they will have the proper function and can easily do it for
> you.
>
> Also there is a complementary function: unix2dos which adds the <cr> and
> linefeed to the end of every line.
>
> Bob
>
>
> On Mon, 11 May 2009, AlexG1 wrote:
>
>>
>> Hello,
>>
>> I'm having some trouble using the fgetl() function on a Windows system.
>> Every line in a Windows file ends with <cr><lf>. While fgetl() ignores the
>> <lf> character it doesn't ignore <cr> (unlike the Matlab version of the
>> same
>> function), which can be problematic in some cases (e.g. when I'm reading a
>> file path and then try to use fopen() on it - I get fid = -1).
>>
>> Is there a function which ignores <cr> completely, or should I shorten
>> every
>> line that is read by 1 character?
>>
>> Thanks,
>>
>> Alex
>> --
>> View this message in context:
>> http://www.nabble.com/fgetl%28%29-on-Windows-tp23483929p23483929.html
>> Sent from the Octave - General mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Help-octave mailing list
>> Help-octave@...
>> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>>
>
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave

Re: fgetl() on Windows

by Benjamin Lindner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Bob Odom wrote:

> Hi Alex,
>
> You can get rid of the <cr> at the end of the line using:
>
> dos2unix file.in file.out
>
> If you don't have access to a Unix or Linux system, there may be a
> Windows version of that function.  If you know anyone with a Linux or
> Unix system they will have the proper function and can easily do it for
> you.
>
> Also there is a complementary function: unix2dos which adds the <cr> and
> linefeed to the end of every line.
>
> Bob
>
>

The mingw32 binary of octave ships with mingw's gcc collection, which
includes both dos2unix and unix2dos. Have a look at the mingw32/bin
subdirectory.

You can also get them sperately from the mingw download page at
sourceforge. It's the "Mingw Utils" package
http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=61599

benjamin

benjamin
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave