You are not logged in.
I am trying to create a variable-length array of strings, so an array of character arrays...
int num = 5;
char *questions = malloc(num * sizeof(char[100]));
memset(questions[1], 0, 100);
sprintf(questions[1], "hi");
If I try to compile this, I get two "makes pointer from integer without a cast" errors, one for the memset function and one for the sprintf function. Does anyone have any ideas? Thanks in advance.
Offline
You're creating an array of characters, not an array of strings. Also, questions[1] is the second element of the array, which may not be what you want.
char** questions = malloc(sizeof(char*[num]));
int i;
for (i = 0; i < num; i++) questions[i] = malloc(sizeof(char[100]));
Or somesuch. It's late, and I probably hid a big mistake in there.
Last edited by pauldonnelly (2008-10-18 05:48:53)
Offline
It seems to work; thanks!
Offline