mardi 5 mai 2015

malloc for a 2D array

I have declared a global array, char *people[][2]. The purpose of this array is to hold people's first and last names in the form of:

people[0][0]          = "John"           people[0][1]          = "Smith"
people[1][0]          = "Frank"          people[1][1]          = "Jones"
...                                      ...
people[NumOfNames][0] = "Lisa"           people[NumOfNames][1] = "Murray"

Where NumOfNames is an integer variable calculated in a function within my program. Once this value has been stored for NumOfnames, how can I use malloc to allocate memory to people so that it is of size [NumOfNames]*[2]?

Aucun commentaire:

Enregistrer un commentaire