Okay so I'm currently learning C in Visual Studio 2010, and my goal is to allocate enough memory for a plane structure (containing air traffic controller simulation info) of "num" elements. Below is the code I have for that function. The setData is an already completed working function that stores individual plane struct data. MY QUESTION: how do I make it call setData "num" amount of times and return all the elements to the main? My thinking was loop the data to store per element put when I return its the first byte of allocated memory....which is element one instead of all of them.
struct plane* list_intialize(unsigned int num)
{
struct plane * ptr;
int i=0;
ptr = (struct plane *) malloc(num * sizeof (struct plane));
for(i=0;i<num;++i)
setData(&ptr[i]);
return ptr;
}
HERE IS MY INSTRUCTIONS FOR THIS FUNCTION: Here an unsigned integer listsize is passed to this function you are to create a link list of size listsize. This will be performed by repeated use of malloc and calling setData to initialize the data into the struct plane fields. Each time you place the process in the list you need to place it so the list is sorted by the field distance (in ascending order). you return the head of the list
I have the ascending order sort I just need the rest