Anonymous
public text v1 · immutablei use this struct to hold a list of strings and the respective frequencies of them
struct trie
{
int existe;
int frequencia;
trie *prox[numElem] // number of chars in abc ... z
}
...then i will need to copy them to arrays
one for the strings and other for its frequencies ...
and here's the problem. segmentation fault :(
here is the function i use:
void copia(trie *t, char *cadeia, int n,char *pal[], int freq[])
{
int j;
if (t->existe)
{
int pos = 0;
*cadeia=0;
pal[pos] = cadeia-n;
freq[pos] = t->frequencia;
pos++;
//printf("%-20s%10d\n",cadeia-n,pos);
};
for (j=0;j<Nel;j++)
{
if (t->prox[j]!=NULL)
{
*cadeia = j+Minel;
copia(t->prox[j],cadeia+1,n+1,pal,freq);
printf("teste\t");
}
};
and here the main where the function is called...
main ...
if (!strcmp (comando, "c")) {
char *pal[100];
int freq[100];
copia(t,v,0,pal,freq);
int i;
for(i=0;i<100;i++)
printf("%s\t%d ",pal[i], freq[i]);
}
i wanted to print it to teste if everything worked ok but i get a segmentation faul.
i am newbie at #c. can you help me?