All pastes #512198 Raw Edit

Someone

public text v1 · immutable
#512198 ·published 2007-05-26 19:37 UTC
rendered paste body
i 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]);   //// ERRO IS HERE line 37 of triemain.c
}

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?

#0  0xb7e3ec23 in strlen () from /lib/tls/i686/cmov/libc.so.6
#1  0xb7e110cb in vfprintf () from /lib/tls/i686/cmov/libc.so.6
#2  0xb7e16653 in printf () from /lib/tls/i686/cmov/libc.so.6
#3  0x08048a26 in main () at triemain.c:37