Hey guys,
how do I put the cursor at the beginning of a certain row,
for example to read the fifth entry of a csv file?
Thanks,
Jeff
(deleted in edit)
Hey guys,
how do I put the cursor at the beginning of a certain row,
for example to read the fifth entry of a csv file?
Thanks,
Jeff
(deleted in edit)
Last edited by De_Lėtzeboier; 02-03-2008 at 11:55 AM. Reason: unappropriate
Sorry, can't reply in bad english, or in French or German, but I'll try in "simple english". Also, this is an english speaking forum, so discussing in other languages is probably not the most appropriate.
CSV files (as standard) don't have a fixed size per "row", so you need to basically count the number of rows as you read through them. It is possible to store the starting position of each row, should you wish that, and "remember where a row is".
Using fgets() to read each line is the simplest form.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Actually, "simple english" is what I prefer, it's most accurate to talk about programming etc.
However, since this is not a linguistic forum, let's get back to the topic:
Doesn't fgets() only read 'till a space? So, if I understand well, I shall use fgets() (n-1) x m times, where n ist the cardinal of the corresponding row and m is the number of space-separated strings in each row, right?
Thanks,
Jeff
(and sorry for the languages P.S.)
You could loop through four stream.getline()s which should leave you at the start of the fifth line.
Alternatively, there is a GNU extension, getline(), to cstdio, which you could also use, but of course, it's an extension, therefore non-standard.
Yes, sorry, missed that it was C++ rather than C, so getline() is the right function to use.
Both fgets() and getline() reads until either the limt of the buffer is reached, or a newline is found, so assuming your data buffer is large enough to read an entire "row", it should be fine to read using either function.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Ok, thanks to all!
I'll try it out and if it works, I'll close the thread...if I find out how...
Jeff
Threads here are only closed when the moderators think they are "abused". Just responding with "my problem solved" usually is the "end" of the thread.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
k
thx
my problem solved
thx, good forum(Y)