I need to execute a function that returns array of a specified struct with variable length. Then I should loop through the returned array.
example struct :
typedef struct student {
int id;
char *name;
int grade;
} Student;
function prototypes 1 :
Student *students;
students = findStudentByGrade(int grade);
function prototypes 2 :
Student *students;
int retval = findStudentByGrade(&students, int grade);
I am bit confused on above methods. How can correctly define a array of struct? call function ? and loop through it untill end? Can some one help me please.
specified struct with variable lengthwhat do you mean by that ? Your structure size would be 2+2 [char pointer]+2 = 6 , you are just storing the pointer to char in struct.specified structmean the struct which I have shown in code.Studentstruct Student, but how it is of variable length ?