From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

reading from file into array of structures

Solved!
Go to solution

I would like to read from file into  array of structures. The file can be organized as one structure per line:

3000,3200,3,17,1,1,3

3201,3400,3,18,5,2,1

...

My intent is to initialize some integer constants depending on a frequency band given by first two elements in structure as follows:

I'm not sure how to initialize the structure from the file.

 

typedef struct {
    double lowFreq;
    double highFreq;
    int doubler;
    int PreN;
    int mult;
    int N;
    int cpGain;
} Band[numBands];
    
    for (i = 0; i = numBands; i++) {
        if ((inFreq >= band[i].lowFreq) & (inFreq <= band[i].highFreq))
            {
                doubler = band.doubler;
                PreN = band.PreN;
                mult = band.mult;
                N = band.N;
                cpGain = band.cpGain;
            }
    }

Thanks

0 Kudos
Message 1 of 3
(2,132 Views)
Solution
Accepted by topic author the_emc_guy

Given the file structure you have reported, I see no way of reading it other that using either standard C functions (fopen, fgets, fclose) or their equivalents in the CVI Formatting and I/O Library (OpenFile, ReadLine, CloseFile). The help file for the functions include links to some example programs that may help you to design your own code.



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 2 of 3
(2,116 Views)

That's what I'll do.

Thanks.

0 Kudos
Message 3 of 3
(2,095 Views)