I'm creating a class BookType that will store information about books. Each
book type can have up to 4 authors.
I defined a new type for an array of char:
typedef char array4_t[25];
This will hold 25 characaters
I declared a 2 dimensional array of char in BookType:
char m_authors[4][25];
I could have used vector but this just a practical exercise.
I have a SetAuthors function which sets the authors which accepts a pointer
to a pointer toi char (char**). It works fine.
I also have a function GetAuthors that returns a pointer to array4_t:
array4_t* BookType::GetAuthors()
{
return m_authors;
}
In my test program I want to loop through the array of strings and print the
authors. I've done this but it doesn't work well:
array4_t* authors = books[i]->GetAuthors();
while (*authors != NULL)
{
printf(" %s ", authors);
authors++;
}
This goes into an infinite loop. Not sure why.
Can someone please tell me the best way to return a pointer to an array of
char and how to iterate through the array without using vector (or another
STL container)?