Visual C++

Moderators: Lundin
Number of threads: 379
Number of posts: 695

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Reading Data From a CSV or Flat File and Creating a Dataset Posted by mjaynotts on 5 Apr 2009 at 11:08 AM
Hi, I am creating an application where i want to populate a dataset from a CSV file once i have clicked on a load button and chosen the location of the file!!

For example:

If i have a csv containing n columns and m rows. where the first row of the file contains the column headers.

How do i read it in so i can store it in a dataset. I then want to be able to:

- Display the dataset on a datatable;
- Perform a number of tasks on the data:

i.e. do i=1 to (number of rows);
Column_new=Column1 + Column2;

- output the results (column_new) into a new data table.

Each time a file is read in i want it to be able to hold different numbers of columns and rows!!

I am completely stuck any help would be really appreciated..

mj







Report
Re: Reading Data From a CSV or Flat File and Creating a Dataset Posted by Malcolm_McLean on 8 Apr 2009 at 2:54 AM
CSV files can be surprisingly tricky to parse, because the loader has got to account for all sorts of errors.

However there is a loader on my website (here) in the fuzzy logic trees section. Annoyingly, it needs a slight change because not-a-number is handled differently on different compilers.

Once you've got the loader, you can create a 2D array by calling malloc() to create double ** pointing to the rows, then malloc() to create a double * for each row. Then you populate the 2D array from the CSV object that the loader created.

Then you forget about the loader and do all you manipulations of the data.

Writing a CSV file is much easier than reading one. You simply call printf() in a loop, remembering to terminate the last data item in each rown with a newline instead of a comma.

Report
Re: Reading Data From a CSV or Flat File and Creating a Dataset Posted by Malcolm_McLean on 8 Apr 2009 at 2:55 AM
CSV files can be surprisingly tricky to parse, because the loader has got to account for all sorts of errors.

However there is a loader on my website (here) in the fuzzy logic trees section. Annoyingly, it needs a slight change because not-a-number is handled differently on different compilers.

Once you've got the loader, you can create a 2D array by calling malloc() to create double ** pointing to the rows, then malloc() to create a double * for each row. Then you populate the 2D array from the CSV object that the loader created.

Then you forget about the loader and do all you manipulations of the data.

Writing a CSV file is much easier than reading one. You simply call printf() in a loop, remembering to terminate the last data item in each rown with a newline instead of a comma.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.