Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C (http://www.programmingforums.org/forum60.html)
-   -   csv file. what is better a 2D or a 3D array? (http://www.programmingforums.org/showthread.php?t=11424)

beginnerCCC Sep 29th, 2006 1:34 AM

csv file. what is better a 2D or a 3D array?
 
how can i read the following data into an array.
and which array dimension is better a 2D or a 3D array.
i want to save it to an array so i can get access to any element
this data is in a csv file.
i can open and read the file. but i cant read the colmuns that i want.
can anyone help me doing it?

BHP,"27 Aug 2002",9.53,9.56,9.45,9.45,8117955
BHP,"26 Aug 2002",9.45,9.48,9.4,9.48,6990617
BHP,"28 Aug 2002",9.54,9.55,9.4,9.44,12771227
BHP,"29 Aug 2002",9.31,9.31,9.21,9.27,11986227
BHP,"30 Aug 2002",9.21,9.23,9.11,9.11,19340245
BHP,"02 Sep 2002",9.15,9.23,9.05,9.23,8681758
BHP,"03 Sep 2002",9.14,9.25,9.14,9.24,7833427
BHP,"04 Sep 2002",9,9.01,8.88,8.9,18221850

bivhitscar Sep 29th, 2006 1:40 AM

I'd use a 2D array of char. First, read each line with fgets(), then use the string.h function strtok() to seperate the values, using the comma as your token.

DaWei Sep 29th, 2006 1:42 AM

See this page, scroll down to the CSV Parsing Class. Scorp is a sometime-contributor to this site, and his work is good. It's C++, so not entirely applicable to C, so if this doesn't help, post back.

beginnerCCC Sep 29th, 2006 2:30 AM

sorry i cant really understand what they are doing in c++.
i am new at c lol.
can u plz expalin it to me.
or give me a hint code on how to do it.

regards.

bl00dninja Sep 29th, 2006 3:51 AM

lol!!!!!!!!!!!!!!!!1111ONE

i uze a ary of 43,729 dims yo!!!!!!!!!!!!!!!!!!!!!!

ur sure to hv a betr tym with theeeeeeeeese 1's!

use whatever dimension of array is most useful for your data manipulation/extraction. also, use real words.

Narue Sep 29th, 2006 9:21 AM

>how can i read the following data into an array.
First ask yourself if you need it all in an array. Is it not possible to process each line individually?

lectricpharaoh Sep 29th, 2006 9:30 AM

Quote:

Originally Posted by Narue
>how can i read the following data into an array.
First ask yourself if you need it all in an array. Is it not possible to process each line individually?

Then, if you decide you still need it in an array, consider an array of structures. This would allow you to give meaningful names to each structure member (I have no idea what those numbers or dates mean), and you could store the entire thing in a single-dimensional array. This is certainly a much easier solution than trying to use dynamically-allocated multi-dimensional arrays as a programmer who is (apparently) relatively new to C.

Try searching for tutorials on 'struct' on the net (or in your C books, if you have any). Then come back and ask if you have any more questions. I notice that a lot of the time, novices either greatly simplify or greatly complicate the problem; I have a feeling you're doing the latter, and making it a lot harder than it needs to be.

beginnerCCC Sep 29th, 2006 11:38 AM

yeah true. iam new to c.
but the problem is that what i learnt was to allocate dynamic memory to any array i use, bcz the program can be used with different numbers of lines and columns. so i thouhgt its better to do it this way.
i think about using a 2D array....
i am gonna try now n i ll get back to u guys thanks.

DaWei Sep 29th, 2006 12:18 PM

Let me be up front. English may not be your first language, which would be an excuse. You haven't said. If it is, then you are indulging in what some call AOL-speak, but what I call lazy-ass-speak. I, for one, won't contribute much effort for a lazy-ass. If you try it with the compiler, you won't get far either.

beginnerCCC Sep 29th, 2006 9:54 PM

english is not my first language. i am french.
but trying to learn more and more of english.


All times are GMT -5. The time now is 1:12 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC