![]() |
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 |
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.
|
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.
|
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. |
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. |
>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? |
Quote:
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. |
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. |
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.
|
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