Solved

function procedure design

Posted on 2006-11-12
4
221 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
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…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

911 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

22 Experts available now in Live!

Get 1:1 Help Now