LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading csv file into arrays

Hi. This is my first post. I am just starting to learn CVI. I have a
text file with eight fields separated by commas (a csv file). I want
to read the file and feed the values into eight different one
dimensional arrays. I can't control how many rows will be in the file.
Can anyone post a some code to help me.

Thanks!

Scott
0 Kudos
Message 1 of 4
(7,443 Views)

Hi Scott,

 

Welcome to the community! I hope you enjoy your time with CVI.

 

As for your question, I won't be able to post you a working code right now, since I do not have CVI on this computer.

I'm sure you will get a full solution soon.

 

There are many sample projects in CVI installation. They are grouped according to application.

I'm sure you will find one matching your needs.

 

They are also a good way to get acquinted with the environment and the libraries.

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 4
(7,429 Views)

Welcome from me too, Scott!

CVI is a powerful instrument for you to develop high quality applications.

 

Being in the same situation as ebalci, I cannot give you a complete solution, anyway I would approach your problem this way:

 

  1. Open the file to read from: you can use FileSelectPopup () to browse computer resources and locate your .CSV and OpenFile () to actually open the file
  2. Count file lines using a loop with ReadLine (): if return value is -1 the file is finished, otherwise count the line
  3. Rewind the file with SetFilePos ()
  4. Dynamically allocate memory for your arrays with calloc ()
  5. Loop again reading the file and use Scan to scan values from the line read to the arrays
  6. Close the file

Starting from this conceptual framework you can study the documentation regarding the commands I have pointed you to and develop your application. Feel free to post some more questions if you have any doubt on this and other items.

 

Also, you should treasure ebalci suggestion: CVI comes with a lot of good examples and a powerful searching function with which you can locate the most appropriate code that can address your doubts; simply use Find examples... function in Help menu.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 3 of 4
(7,426 Views)

Hi Scott

 

Put something together for you (see attached) using some old code I had lying around.  You'll need to add error checking and handling but its pretty close otherwise.  As the guys in the earlier post suggested you should really go for dynamically allocated storage for your arrays. I have avoided this to keep things simple, but once you've got the file reading concept expand it to malloc and free as suggested.

 

I have never used it but you might want to look into the FileToArray() function.

 

Regards

 

Steve

Message Edited by Cheesey on 11-23-2009 08:07 AM
0 Kudos
Message 4 of 4
(7,406 Views)