I haven't been brushed up on my Data Structures and I am encountering a problem using structures.
I want to create a structure that will be pointers to values from an array I take from an input file.
Say for example I created a structure here:
struct complexnums {
float * real; //A ptr to real list
float * imag; //A ptr to imag list
};
int main()
{
//Lets say this is an array I have taken from file input
float real [] = {1.0, 2.0, 3.0, 4.0};
float imag [] = {0.5, 1.0, 1.5, 2.0};
//How can I assign the structure ptr's to these arrays?
//Do I do it like this?
complexnums complex = {&real[0],&imag[0]};
}
Given the example, above is that the correct way to assign the values to it? Will the struct actually get the pointers to those values above?
Also I was looking at a sample of how a struct look like and this person did this.
typedef struct {
int sample;
int *test1;
}
struct1, *struct2;
What is the difference between struct1
and struct2
?
Sorry and let me know if this is understandable. If not I'll try to edit it the best I can.