Try using an initial malloc line before the while loop where you call realloc. (I think you have to malloc before you can realloc). Unless, of course, palabras was malloced before you passed it to loadWords (I'll get to that at the end).
As Elysia points out, count is uninitialized so probably much more than zero to start with, which will be a significant problem. Then I think you want to concatenate buff onto secbuff in the while loop. You can use strlen instead of sizeof in realloc if the words may be different sizes, and error check:
Code:
int count=0, int len=1;
char *secbuff=malloc(1); // that one byte will be the null terminator
secbuff[0]='\0' // otherwise the first strcat will segfault
if (secbuff==NULL) exit (-1);
[...]
while(feof(diccionario)==0){
fgets(buff, 6, diccionario);
len+=strlen(buff);
if ((secbuff = realloc(secbuff, len))==NULL) exit (-1); // however you would deal with this
strcat(secbuff,buff);
count++;
}
palabras=secbuff;
Notice that i didn't use palabras in the loop, since you are setting it to point to secbuff afterward anyway. Realize that when you used secbuff=realloc(palabras...), which is fine, that secbuff then points to palabras, so there was no point in the subsequent palabras=secbuff.
I don't actually know where palabras came from, what could be in it, or if it was already malloced, but I'm assuming "none of the above" since that will get thrown away by doing all this (in the original, and in my corrected variant).
Some people may tell you it is bad to call realloc with a return pointer that is the same as the one passed, secbuff=realloc(secbuff...). Really, this is only a problem if realloc fails, and if realloc fails your computer is out of memory and probably about to crash, so you might as well just exit (or at least "return -1" out of the function).
Of course, the list of words in palabras will not have any spaces between them this way! You will have to find a solution to that. Also, if you know how many words there are, or can find out before you call loadWords, you could pass in a 2D char* (a list of strings) and use that. This actually simplifies the memory allocation:
Code:
char *palabras[20]; // 20 words max
int X=loadWords("\folder\there\diccionario",palabras,20)
int loadWords(char *path, char **palabras, int max){
FILE *diccionario;
diccionario = fopen(path,"r");
int count=0;
char buff[7];
printf("Empezando a cargar dic..");
while(feof(diccionario)==0 && count<max){
fgets(buff, 6, diccionario);
if ((palabras[i]=malloc(strlen(buff)+1))==NULL) exit (-1);
strcpy(palabras[i],buff);
count++;
}
if(fclose(diccionario)!=0){
printf("Error cerrando dic");
}
printf("Palabras cargadas");
return count;
}