Solved

function procedure design

Posted on 2006-11-12
4
220 Views
Last Modified: 2010-04-15
hi,
I have a program like below:
the problem is the backtrack() will return me more than one set of (newt[N][i][j] != 0), but only first set goes to addpath(N, i, j). how can I let the program run every set of  (newt[N][i][j] != 0)?


---------------------------------------
main ()
{
backtrack();
system("pause");
return 0;
}

void backtrack(void)
{
   for (i=0; i<3;i++){  
      for (j=0; j<3; j++) {
           if (newt[N][i][j] != 0)
           {    
               addpath(N, i, j);        
            }//end if
       }// 3rd for      
      } // 2nd for  
}
----------------------------------------------------------------------------

<ps> the addpath(N, i, j) will continue call other functions.....but I am sure that the final function is looks like

void addpath (int s, int i, int j)
{
  if( s == 0 )
  {
    printf("final path is %d%d%d : \n",s,i,j);
    printf("finish!!\n");-------------------------------------------->> end here
    return;
  }
   call other functions....
}
0
Comment
Question by:rmtogether
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 400 total points
ID: 17926625
Hi rmtogether,

Where are i and j declared? If they are declared global then they are probably being changed elsewhere.

Paul
0
 

Author Comment

by:rmtogether
ID: 17927343
thanks PaulCaswell

I got it... by the way, can I ask you last question?

Since I might got couple sets of i , j (newt[N][i][j] != 0) to put in addpath(N, i, j), how can I design my addpath() to know each set of i, j and how many times ddpath(N, i, j) has called

<ps>
this is because my program need to know each set of i,j and also addpath()  will respond different actions every time called


----------------------------------------------------------
           if (newt[N][i][j] != 0)
           {    
               addpath(N, i, j);        
            }//end if


void addpath (int s, int i, int j)
{
  if( s == 0 )
  {
    printf("final path is %d%d%d : \n",s,i,j);
    printf("finish!!\n");
    return;
  }
   call other functions....
}
0
 
LVL 13

Assisted Solution

by:marchent
marchent earned 100 total points
ID: 17928272
>>how many times ddpath(N, i, j) has called
put some global variables
int counter = 0;
int pathN[100];//say maximum is 100
int pathI[100];
int pathJ[100];

and inside ddpath() add thease lines.
pathN[count] =s;
pathI[count] = i;
pathJ[count] =j;
count++;//increase the counter

to view the call informations use this function
void show()
{
   printf("Number of times ddpath called = %d\n",count);
   for(int i=0;i<count;i++)
      printf("Sets of values (%d,%d%d)\n",pathN[i],pathI[i],pathJ[i]);
}

~marchent~
0
 

Author Comment

by:rmtogether
ID: 17933433

thanks, marchent

since this is different question, I guess i should closed this one and open another.

I have open another question, base on this idea...could you please take a look. thanks in advance.

http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_22059132.html
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now