Click to See Complete Forum and Search --> : Text file manipulation?
bdg1983
02-24-2001, 07:18 PM
Is there an easy way (in C) to do things like get the total number of lines in a flat text file, seek to a specific line, and other such things that seem so simple? The only thing I can think of is looping through the file and marking the file position after \n as the start of a line, but this seems needlessly complex. Is there an easier way?
david
02-24-2001, 09:40 PM
I'd hope to hell so!!! I'm 99% sure that there are in PHP, so I'd hope there's something along those lines in C as well :)
jemfinch
02-25-2001, 02:18 AM
Yeah.
In fact, they make entire applications to do this. Two such applications are Python and Perl.
:D
Jeremy
Sterling
02-25-2001, 12:30 PM
No, there is not an easy way to do that in C. As Jemfinch said, Perl and Python are really designed for easy manipulation of files. C's way of doing things is both a strength and weakness of the language - it can, in theory at least, do more, but it is also harder on the programmer.
bdg1983
02-25-2001, 04:30 PM
while(1)
printf("Doh!");
:(
klamath
02-25-2001, 07:32 PM
Keep in mind that line endings on different platforms are different (e.g. "\n" on UNIX, "\r\n" on Win32, etc).
Ruby (http://www.ruby-lang.org) is also very good at parsing text files (better than Python).
jemfinch
02-25-2001, 10:41 PM
Ruby (http://www.ruby-lang.org) is also very good at parsing text files (better than Python).
How so?
Jeremy
Ruby is also very good at parsing text files (better than Python).
How so?
Jeremy
Didn't we do this whole Ruby/Python "my language can beat up your language" thing just last week? If we're gonna do repeats, I vote for vi/emacs; that one's more fun and more people can play.
Emacs suckZ! vi is god's gift to programmers!
:)
YaRness
02-26-2001, 12:40 PM
you know, i'm amazed. i thought python was the unspoken-of bastard child of Java and BASIC (or maybe Ada..., although i know ada lets you reduce "ada.text_io.print" to "print"), but in terms of ugliness, ruby wins hands down (this implies nothing about function; i haven't even touched it yet, but UGH).
:cool: Perl :cool: Irritating the sh!t outta people since before some hackers were born.
jemfinch
02-26-2001, 01:28 PM
Originally posted by kmj:
Didn't we do this whole Ruby/Python "my language can beat up your language" thing just last week?
Sure, but you won't find me making unsubstantiated claims about the two.
Jeremy