LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Struct Use

Dear alls,
 
I'm a new user in Labwindowsand I've problem with the Structs,
 
I would like to make (and use) a struct
 
typedef struct
 {
 char mau[30];
 double valor;
 } estructura;  

estructura *estruc[10];
 
 
But I don't know what happens, It isnot working properly.
 
 
I would like to define a struct with
 
double valor and char mau[30].
 
But after to this, I need 10 times of this struct (I don't know if Is it clear?).
 
For example, Is it possible to use:
 
estruc[1]->mau="Test";
estruc[1]->valor=123.12;
estruc[2]->mau="Test2";
estruc[2]->valor=999.99;
 
 
Do I need the malloc
0 Kudos
Message 1 of 2
(2,928 Views)
With some little adjustment your code should work properly.
 
When defining the struct:
typedef struct {
 char mau[30];
 double valor;
} estructura;  
estructura *estruc;
 
When allocating memory for the struct:
estruc = calloc (10, sizeof (estructura));
I do prefere calloc to malloc since calloc inizializes all fields to zero.
 
When using struct elements:
strcpy (estruc[0].mau, "Test");
estruc[0].valor = 123.12;
 
Hope this helps
Roberto


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?
0 Kudos
Message 2 of 2
(2,917 Views)