Thread: error in a for loop

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    63

    error in a for loop

    I am having an error in my code below and cant figure out why. It must be some stupid smalle error. After doing a lot of testing, I have conluded that the first time through goes fine. But when it loops through a subsequent times it automatically returns 0, though the if statement is not true. Any idea what is wrong here?

    edit: setCardinality returns the size of the array.

    Code:
    int isSubset(int a[], int b[]){
    	
    	int isMember(int x, int a[]);
    	int setCardinality(int a[]);
    	int i;
    
            /*problem somewhere in here, returns 0 on loops after first*/
    	for(i=0;i<=setCardinality(b);i++){
    		
    	if((isMember(a[i],b))==0){
    			return 0;
    		}
    	}
    
    	return 1;
    }
    Last edited by saahmed; 03-09-2006 at 06:59 PM.

Popular pages Recent additions subscribe to a feed