?
Solved

function procedure design

Posted on 2006-11-12
4
Medium Priority
?
230 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 1600 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

840 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