Thread: pattern checking in a string question..

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    pattern checking in a string question..

    This function needs to check if the sting is a polynomial .
    It check it for some sort pattern. If this string is not builded by this pattern then it return
    0. else it returns 1

    i translated this function from java

    can you tell me what pattern it checks in this string??
    (variable length is the length of the string)
    Code:
     
    int checkPoly(char[] str,int length)
    	{
    	  int result;
    	  result=false;
              int index;
               int index2;
                 int index3;
    
    
     
    
    	  for( index=0;((index<length)&& (((str[length-1]>'0')&&(str[length-1]<'9')))));index++)
    	   {
    		  if((str[index]=='(')&&(str[index+1]!='('))
    		  {
    			
    			  for (index2=0;index2<length;index2++)
    			  {
    				  if(str[index2]==')')
    				  {                                        
    					  if((str[index2+1]=='x')&&(str[index2+2]=='^')&&((str[index2+3]>'0')&&(str[index2+3]<'9'))))
    
    					  {
    						  result=1;
    						  index=length;
    						  for (index3=index2+2;((index3<length)&&(((length)-(index3+2)!=0)));index3++)
    						  {							 
    							  if(str[index3]=='(')
    							  {
    								  if(str[index3-1]=='+')
    								  {									  
    									  index3=length;
    									  result=1;
    								  }
    								  else
    								  {
    									  index3=length;
    									  index2=length;				
    									  result=0;
    								  }
    								  
    							  }else{}
    						  }
    					  }else
    					  {
    						  result=0;
    						  index2=length;
    						  index=length;
    						  
    					  }
    				  }else{}
    			  }
    		  }else {
    			  result=0;
    			  index=length;
    			  }
    		 
           }
    	  return result;
    	}
    Last edited by transgalactic2; 12-26-2008 at 12:12 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  5. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM