July 31st, 2009, 10:25 AM
#1
allocating bidimensional matrix
hi all!! I need to create a function that by reference reallocate an asymmetrical bidimensional
character matrix...
I've done something like that but it crash...
================================CODE================================
#include <iostream>
using namespace std;
void add(char ***list, int n, char *person)
{
static int GlobStrLen = 0;
*list = (char**) realloc(*list, GlobStrLen * sizeof(char**));
*list[n] = (char*) malloc (strlen(person) + 1);
strcpy(*list[n], person);
GlobStrLen += strlen(person) + 1;
}
int main()
{
char **list = NULL;
int n = 0;
add(&list, 0, "jack");
printf("list[0]: %s\n", list[0]);
n++;
add(&list, 1, "jeff");
printf("list[1]: %s\n", list[1]);
return 0;
}
================================END CODE============================
thank you for yours replies!!!
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks