Thread: problem getting result when calling a function

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    27

    problem getting result when calling a function

    Hi all,
    I have sorted out my earlier problem but now have a different. I have defined an array of objects called LineArray. Each of these objects has an array called m_XYCoOrds[][] which hold ten x,y co-ordinate points. The 2nd dimension in the array holds x points at 0 and y points at 1. e.g. the first X point would be found by
    m_XYCoOrds[0][0] and the y at
    m_XYCoOrds[0][1].
    The function ncrosses takes two points (x1,y1 and x2,y2) as arguments and checks to see if they cross any other lines that are defined as illegal in the map. The function ncrosses looks like
    Code:
    int ncrosses(int x1,int y1,int x2,int y2)
    {
    struct lineSeg *l1;
    int i,j,count=0;
    
    	l1=coords2lineSeg(x1,y1,x2,y2);
    
    	for(i=0;i<MSIZE;i++)
    	{  for(j=0;j<NSIDES;j++)
    		if(crosses(l1,lmap[i].ln[j]))
    		{count++;
    		 /*printf("hit %d ",i); */   /* only need to know about one line
    				      crossed to know zone crossed or partially
    				      crossed, could modify to get more info.*/
    		    break;
    		}
    	}
    	free(l1);
    	return count;
    }
    the function crosses called in this function is the one that looks for the crossed lines. I know these functions work because, as you might be able to tell from the comments they are from an original piece of work in C. When I call ncrosses I want to store the value count in an object variable LineArray[0].m_LineCrosses.

    And this is where the problem is coming from.
    Because each line object has 10 different xy points it is necessary to call ncrosses 9 times for each object. I set up a simple for loop to do this when the document initialises.
    Code:
    int t=0;
    		while(t<9)
    		{
    				x1 = LineArray[i].m_XYCoOrds[0][0];
    				y1 = LineArray[i].m_XYCoOrds[0][1];
    				x2 = LineArray[i].m_XYCoOrds[1][0];
    				y2 = LineArray[i].m_XYCoOrds[1][1];
    				
    				temp = ncrosses(x1,y1,x2,y2);//get the number of lines crossed
    				total = total + temp;
    				t++;
    		}
    		LineArray[i].m_LineCrosses = total;
    the i in LineArray is simply because I am working my way through the array calling this for every line object.
    The problem is that the value is always whatever I initialise total to be. e.g. if i set the line total=400; before calling this section of code LineArray[i].m_LineCrosses always equals 400. Its almost as thought the line LineArray[i].m_LineCrosses = total; does not exist. Any thoughts would be much appreciated.
    Cheers
    Dylan

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    27

    Don't worry

    Okay don't worry I have run some tests and the function always returns 0 so there must be a problem within the function.
    sorry to waste any time

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem calling a function
    By JOCAAN in forum C Programming
    Replies: 4
    Last Post: 11-01-2008, 12:17 PM
  2. problem calling a function from a thread
    By BrownB in forum Windows Programming
    Replies: 8
    Last Post: 12-13-2007, 07:55 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. problem with function calling
    By Andystudent in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2004, 06:12 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM