Hi Iam getting a segmentation fault in the following program, it would be great if you can suggest where exactly iam going wrong, here Iam trying to extract substrings from a string and store it in a array of strings, please note the recursive call in the function.
Code:
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<stdlib.h>

int k=0;
int p=1;
void parser(char in_str[][25],char out_str[][25]);





int main()
{
    
    char inputexp[500];
  
   char label[50][25];
      
      
          printf("enter expression");
    scanf("%s",inputexp);
    
    strcpy(label[0],inputexp);
          
 
    
    parser(label,label);                                                                                                                          
     
    return 0;
          
       getchar();
    getchar();
}        
     
     void parser(char in_str[][25],char out_str[][25])
    {
           while(in_str[k]!= '\0')
           {
           int len=strlen(in_str[k]);
           int openbrac_count=0,closebrac_count=0;
           int i=0;
           int from=0;
           while(i<len)
          {
                      while(i<len && in_str[k][i]!=')')
                      {
                       if((in_str[k][i]=='('))
                       {                                                                                                                
                       openbrac_count++;
                       }
                       i++;
                      }
                       while(i<len && in_str[k][i]!='(')
                       {
                               if(in_str[k][i]==')')
                               {                                                                                                                
                               closebrac_count++;
                               }
                                            
                               if(openbrac_count==closebrac_count & openbrac_count != 0)
                               {
                                  strncpy(out_str[k+1],&in_str[k][from],i-from);
                                  p=p+1;
                                  
                                  if (in_str[k][i+1]=='&' || in_str[k][i+1]=='|')
                                  {     
                                        
                                        from=i+2;
                                        
                                  }                         
                                  
                               }
                                                                                 
                                i++;
                                    
                        }
                if (in_str[k][0]=='G')
                {
                   strncpy(out_str[p+1],&in_str[k][2],strlen(in_str[k])-2); 
                   parser(in_str,out_str);
                 }
                 
                 if (in_str[k][0]=='F')
                {
                   strncpy(out_str[p+1],&in_str[k][2],strlen(in_str[k])-2); 
                   parser(in_str,out_str);
                 } 
                  
                  if (in_str[k][0]=='X')
                {
                   strncpy(out_str[p+1],&in_str[k][2],strlen(in_str[k])-2); 
                   parser(in_str,out_str);
                 }                                 
                 }
           
           k++;
           
           }
           
           }

Last edited by shabbir; 23Jun2009 at 16:16.. Reason: Code blocks