?
Solved

function procedure design

Posted on 2006-11-12
4
Medium Priority
?
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 opening and writing to files 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.

770 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