Re: [Vala] read file line by line
- From: Luca Bruno <lethalman88 gmail com>
- To: Mic <mictadlo gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] read file line by line
- Date: Fri, 13 Apr 2012 12:19:39 +0200
On Fri, Apr 13, 2012 at 12:18 PM, Luca Bruno <lethalman88 gmail com> wrote:
On Fri, Apr 13, 2012 at 12:10 PM, Mic <mictadlo gmail com> wrote:
Hello,
Is this the best and fastest way to read a file line by line?
*static int main (string[] args) {*
* FileStream infile;*
* infile = FileStream.open(args[1], "r");*
* char buffer[1024];*
* int count = 0;*
* while (!infile.eof()) {*
* infile.gets(buffer);*
* count++;*
* }*
* stdout.printf("%i\n",count);*
* return 0;*
*}*
Your code is buggy. See:
http://valadoc.org/#!api=glib-2.0/GLib.FileStream.read_line
And also http://valadoc.org/#!api=glib-2.0/GLib.IOChannel.read_line and
http://valadoc.org/#!api=gio-2.0/GLib.DataInputStream.read_line . The
latter should be the most efficient as it's backed by a buffered stream.
--
www.debian.org - The Universal Operating System
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]