I am trying to allocate memory to a 2d character array as I determine its size. (the count is assumed to be an unknown value) it seems to work until something starts to reassign garbage data to the array
0xd28fe280 -> 3
0xd28fe280 -> 3
0xd28fe280 -> 3
0xd28fe280 -> 3
0xd28fe280 -> ���[U
0xd28fe280 -> ���[U
what essentially what I want to do is allocate memory just before I populate the array with strings.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int count = 6;
char **words;
words = malloc(0);
for(int i = 0;i < count; i++){
words[i] = malloc(10);
strcpy(words[i],"3");
printf("%#08x -> %s\n",words[0],words[0]);
}
free(words);
return 0;
}