Thread: Help with function problem

  1. #1
    NewbieUser
    Guest

    Help with function problem

    Okay I am writing a code that will remove the border of an apmatrix and resize it accordingly

    Code:
    void RemoveBorder(apmatrix <int> & M)
    {
    	apmatrix<int> temp(100,100);
    	int Max = M.numrows()-1;
    	for(int i = 0; i < M.numcols(); i++)
    	{
    		M[0][i] = 0;
    	}
    	for(int b = 0; b < M.numcols(); b++)
    	{
    		M[Max][b] = 0;
    	}
    
    	int Total = M.numrows() - 2;
    
    	while(Total > 0)
    	{
    		M[Total][0] = 0;
    		M[Total][M.numcols()] = 0;
    		Total--;
    	}
    
    	int tempOne = 0;
    	int tempTwo = 0;
    
    	for(int v = 0; v < M.numrows(); i++)
    	{
    		for(int s = 0; s < M.numcols(); s++)
    		{
    			if(M[v][s] != 0)
    			{
    				
    				temp[tempOne][tempTwo] = M[v][s];
    				tempTwo++;
    				if(s = M.numcols() - 1)
    				{
    					tempOne++;
    				}
    			}
    		}
    	}
    
    	M = temp;
    	M.resize(tempOne, tempTwo);
    
    	for(int c = 0; c < M.numrows(); c++)
    	{
    		for (int b = 0; b < M.numcols(); b++)
    		{
    			cout << M[c][b] << " ";
    		}
    	}
    }
    Okay for some odd reason I get an infinate loop. I've narrowed it down to the for-loop with the if-statement...can someone tell me whats wrong with it?

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    162
    You will probably kick yourself when you see what you overlooked:
    Code:
    for(int v = 0; v < M.numrows(); i++)
    shouldn't the i++ be v++?

    Also I don't know if it is your intent, but shouldn't the second if statement be a comparison, instead of an asignment?

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    417

    Re: Help with function problem

    Originally posted by NewbieUser
    Okay I am writing a code that will remove the border of an apmatrix and resize it accordingly
    [/code]

    Okay for some odd reason I get an infinate loop. I've narrowed it down to the for-loop with the if-statement...can someone tell me whats wrong with it?

    An Advance Placement programmer :-P

  4. #4
    NewbieUser
    Guest
    Wow that was a really stupid error...no the second if statement is correct...its will determine when to start the next row after the first one is finished....meaning when putting it into another matrix it will know when to change rows when it needs to

  5. #5
    NewbieUser
    Guest
    Okay now I get an illegal vector index...its in the while loop...can someone tell me what part is screwing it up horribly?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 10-29-2008, 06:33 AM
  2. wxWidgets link problem
    By cboard_member in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2006, 02:36 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM