Re: [Vala] Is this a bug or a feature?



Hello,


Attention, the function feof (in C) should not be used to check the end of a file: http://c-faq.com/stdio/feof.html

The correct code:

[indent=2]
init
 var f = FileStream.open("./main.gs","r")
 var a = new array of char[2048]
 while (f.gets(a) != null)
   a[a.length - 1] = 0         /*make it null-terminated*/
   var           /*caste array-of-char to a string*/
   print "%s", ONELINE


2009/3/20 Barry Kauler <bkauler gmail com>:
> I have this simple code, in Genie syntax:
>
> init
>        var f = FileStream.open("/tmp/0setup-raw-db","r")
>        var a = new array of char[2048]
>        while f.eof() != true
>                f.gets(a)                   /*read one line from file*/
>                a[a.length - 1] = 0         /*make it null-terminated*/
>                var           /*caste array-of-char to a string*/
>                print "%s", ONELINE
>
> It reads a text file line by line and prints it. Problem is, it prints
> the last line twice, but only if the last line has a carriage-return.
> It is standard practice in Unix/Linux for the last line of a text file
> to have a carriage-return, so is this a bug? If so, I'll report it to
> bugzilla.
>
> Note, I get this behaviour in Vala 0.5.1 and 0.5.7.
>
> Regards,
> Barry Kauler
> _______________________________________________
> Vala-list mailing list
> Vala-list gnome org
> http://mail.gnome.org/mailman/listinfo/vala-list
>



--
Nicolas Joseph

Responsable de la rubrique GTK+ de developpez.com /
In charge of the GTK+ section on developpez.com

http://nicolasj.developpez.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]