Thread: Finding a 'Proper Subset'

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    14

    Unhappy Finding a 'Proper Subset'

    Hi, I've been having trouble getting a piece of code I've made to find whether a set is a proper subset of another. The code I'm using is the following:

    Code:
    bool contain(bool arrayA[letter],bool arrayB[letter])
    {
    	int i,counter,counter2;
    	counter=0;
    	counter2=0;
    	for (i=0;i<letter;i++)
    	{
    		if (arrayA[i]==arrayB[i]) counter++;
    		if (counter==26) return false;
    		else break;
    	}
    	for (i=0;i<letter;i++)
    	{
    		if (arrayB[i]==true)
    		{
    			counter++;
    			if (arrayA[i]==true) (counter2++);
    		}
    	}
    	if ((counter==counter2)/*&&(counter!=0)*/) return (true);
    	else return(false);
    }
    The problem is, when I run the program, the output always comes out False . Any help is appreciated.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Work out which of the "return false" statements is being invoked, and track back from there.
    Put some printf()'s in there to help debug (or use a proper debugger if you have one).
    eg
    printf ("Returning false because .....\n");
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. tools for finding memory leaks
    By stanlvw in forum C++ Programming
    Replies: 4
    Last Post: 04-03-2009, 11:41 AM
  2. Proper nouns
    By Ducky in forum C++ Programming
    Replies: 12
    Last Post: 12-31-2007, 11:11 AM
  3. Making proper wrappers.
    By bladerunner627 in forum C++ Programming
    Replies: 3
    Last Post: 11-02-2005, 05:18 PM
  4. MFC :: Finding Child Window of a CWnd* Object?
    By SyntaxBubble in forum Windows Programming
    Replies: 2
    Last Post: 09-06-2003, 09:06 AM
  5. How to find the proper divisor?
    By yusiye in forum C Programming
    Replies: 6
    Last Post: 07-24-2002, 01:14 PM