A maze problem

This is a discussion on A maze problem within the C Programming forums, part of the General Programming Boards category; In 20 hours i have to send my assgnment and I still cannot find the problem.Plz if anyone can help ...

  1. #1
    Registered User sELigkari's Avatar
    Join Date
    May 2007
    Location
    Greece
    Posts
    4

    A maze problem

    In 20 hours i have to send my assgnment and I still cannot find the problem.Plz if anyone can help i would be thankfull...
    we stat from the array[0][0] and we want to finish on array[n-1][n-1],we can walk only on 0 cuz 1 is "wall"...
    Here's my code :
    Code:
    #include <stdio.h>
    
    #define size 12
    
    int A[size][size];
    /*Ton ton orisa e3w apo thn main(global)giati ws local sth main
    mou evgaze provlhma pws den ginetai initialized*/ 
    int n,row,col,turn=1;
    
    void turn_right(int turn);
    void turn_left(int turn);
    void facing_wall(int array[][size],int next,int dipla);
    void move_forward(int array[][size],int n);
    
    int next,dipla;
    
    int main()
    {
    
    
    int *ip;
    
    
    
    
    
    printf("size of array\n");
    scanf("&#37;d",&n);	
    
    
    for (row=0;row<n;row++)
    		{
    		printf("give the %d row of the array:",row+1);	
    	     
    		
    		for (col=0;col<n;col++)
    			{	
    			scanf("%d",&A[row][col]);
    			}
    			
    		} 	
    for (row=0;row<n;row++)
            {
                for (col=0;col<n;col++)
                {   
    			
    			ip=&A[row][col];
                printf("%d ",*ip);
    
    			}
    				 	
    		printf("\n");				
    		}
     
    move_forward(A,n);
    
    
    
    
    return 0;
    
    }	
    
    
    
    
    
    
    
    /*To robot eiserxetai pantote apo thn aristerh pleura,
    opote to forward gi' auto einai na kinh8ei pros to telos 
    ths prwths grammhs.*/
    /*==========================================================*/
    void move_forward(int array[size][size],int n)
    {
    int row=0,col=-1,prev=0,cur,j,i;
    int *ip;
    
    
    for (i=0;i<n;i++)
    {
    /*h grammh panw apo ton pinaka*/
    	array[-1][i]=1;
    /*h sthlh aristera tou pinaka*/
    	array[i][-1]=1;
    /*h grammh katw apo ton pinaka*/
    	array[n][i]=1;
    /*h sthlh de3ia tou pinaka*/
    	array[i][n]=1;
    
    	array[0][-1]=0;
    /*
    printf("array[-1][%d]=%d\n",i,array[-1][i]);
    printf("array[%d][-1]=%d\n",i,array[i][-1]);
    printf("array[%d][%d]=%d\n",n,i,array[n][i]);
    printf("array[%d][%d]=%d\n",i,n,array[i][n]);
    */
    }
    
    scanf("%d",&j);
    
    cur=array[row][col-1];		
    printf("outside while row=%d col=%d n=%d cur=%d\n",row,col,n,cur);
    	   
    
    while (row!= n-1 && col != n-1)
    	{
    	
    	
    		 
     /*go right*/
     
    		if(turn==1)
    			{
    
    				printf("next=%d\n",next);
    				printf("dipla=%d\n",dipla);
    				col=col+1;
    				cur=array[row][col];
    				ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);
    				next=array[row][col+1];
    				dipla=array[row+1][col];
    				facing_wall(A,next,dipla);	
    		    }
    		
    
    		
    facing_wall(A,next,dipla);		
    /*go down*/
    		
    		if(turn==2)
    			{
                    //facing_wall(A);
    				//prev=cur;
    				printf("next=%d\n",next);
    				printf("dipla=%d\n",dipla);
    			
    				row=row+1;
    				cur=array[row][col];
    					ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);
    				
    				next=array[row+1][col];
    				dipla=array[row][col-1];
    				facing_wall(A,next,dipla);	
    			}
    
    facing_wall(A,next,dipla);		
    /*go left*/
    		if(turn==3)
    			{
    				printf("next=%d\n",next);
    				printf("dipla=%d\n",dipla);
    				col=col-1;
    				cur=array[row][col];
    				ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);	
    				ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);
    				next=array[row][col-1];
    				dipla=array[row+1][col];
    				facing_wall(A,next,dipla);	
    			}
    
    
    facing_wall(A,next,dipla);
    /*go up*/
    		if(turn==4)
    		{
    				printf("next=%d\n",next);
    				printf("dipla=%d\n",dipla);	
    				row=row-1;
    				cur=array[row][col];
    				ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);
    				ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);
    				next=array[row-1][col];
    				dipla=array[row][col+1];
    				facing_wall(A,next,dipla);	
    		}
         scanf("%d",&j);
    	}
    	return;
    }
    
    
    
    /*stripse de3ia*/
    void turn_right(int turn)
    {	
     
    	turn=1+turn;
    	if(turn==5)
    	{
    		turn=1;
    	}
    
    
    return;
    }
    
    
    /*stripse aristera*/
    void turn_left(int turn)
    {	
     
    	turn=turn-1;
    	if(turn==0)
    	{
    		turn=4;
    	}
    return;
    }
    
    
    
    
    
    
    
    
    /*vrhkame se toixo ? */
    
    void facing_wall(int array[size][size],int next,int dipla)
    {	
    
    		if(next==1 || dipla==0)
    			{
    			turn_right(turn);
    			printf("koitame de3ia\n");
    			}
    		else if(next==0|| dipla==0)
    			{
    			turn_right(turn);
    			printf("koitame de3ia\n");
    			}
    		else if(next==1 && dipla==1)
    			{
    			turn_left(turn);
    			printf("aristera\n");
    			}
    
    return;
    }
    [/edited]
    Last edited by sELigkari; 05-14-2007 at 07:00 PM. Reason: i

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    What's the question again? What doesn't work?

  3. #3
    Registered User sELigkari's Avatar
    Join Date
    May 2007
    Location
    Greece
    Posts
    4
    tYou are right.In my hurry i forgot to write what te problem is.
    It always says that turn=1 and i cannot understand why, so it only moves on the first row (it only changes columns).

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Try this:
    Code:
    include <stdio.h>
    
    #define size 12
    
    int A[size][size];
    /*Ton ton orisa e3w apo thn main(global)giati ws local sth main
    mou evgaze provlhma pws den ginetai initialized*/ 
    int n,row,col,turn=1;
    
    void turn_right(void);
    // Was: void turn_right(int turn);
    void turn_left(void);
    // Was: void turn_left(int turn);
    void facing_wall(int array[][size],int next,int dipla);
    void move_forward(int array[][size],int n);
    
    int next,dipla;
    
    int main()
    {
    
    
    int *ip;
    
    
    
    
    
    printf("size of array\n");
    scanf("%d",&n);	
    
    
    for (row=0;row<n;row++)
    		{
    		printf("give the %d row of the array:",row+1);	
    	     
    		
    		for (col=0;col<n;col++)
    			{	
    			scanf("%d",&A[row][col]);
    			}
    			
    		} 	
    for (row=0;row<n;row++)
            {
                for (col=0;col<n;col++)
                {   
    			
    			ip=&A[row][col];
                printf("%d ",*ip);
    
    			}
    				 	
    		printf("\n");				
    		}
     
    move_forward(A,n);
    
    
    
    
    return 0;
    
    }	
    
    
    
    
    
    
    
    /*To robot eiserxetai pantote apo thn aristerh pleura,
    opote to forward gi' auto einai na kinh8ei pros to telos 
    ths prwths grammhs.*/
    /*==========================================================*/
    void move_forward(int array[size][size],int n)
    {
    int row=0,col=-1,prev=0,cur,j,i;
    int *ip;
    
    
    for (i=0;i<n;i++)
    {
    /*h grammh panw apo ton pinaka*/
    	array[-1][i]=1;
    /*h sthlh aristera tou pinaka*/
    	array[i][-1]=1;
    /*h grammh katw apo ton pinaka*/
    	array[n][i]=1;
    /*h sthlh de3ia tou pinaka*/
    	array[i][n]=1;
    
    	array[0][-1]=0;
    /*
    printf("array[-1][%d]=%d\n",i,array[-1][i]);
    printf("array[%d][-1]=%d\n",i,array[i][-1]);
    printf("array[%d][%d]=%d\n",n,i,array[n][i]);
    printf("array[%d][%d]=%d\n",i,n,array[i][n]);
    */
    }
    
    scanf("%d",&j);
    
    cur=array[row][col-1];		
    printf("outside while row=%d col=%d n=%d cur=%d\n",row,col,n,cur);
    	   
    
    while (row!= n-1 && col != n-1)
    	{
    	
    	
    		 
     /*go right*/
     
    		if(turn==1)
    			{
    
    				printf("next=%d\n",next);
    				printf("dipla=%d\n",dipla);
    				col=col+1;
    				cur=array[row][col];
    				ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);
    				next=array[row][col+1];
    				dipla=array[row+1][col];
    				facing_wall(A,next,dipla);	
    		    }
    		
    
    		
    facing_wall(A,next,dipla);		
    /*go down*/
    		
    		if(turn==2)
    			{
                    //facing_wall(A);
    				//prev=cur;
    				printf("next=%d\n",next);
    				printf("dipla=%d\n",dipla);
    			
    				row=row+1;
    				cur=array[row][col];
    					ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);
    				
    				next=array[row+1][col];
    				dipla=array[row][col-1];
    				facing_wall(A,next,dipla);	
    			}
    
    facing_wall(A,next,dipla);		
    /*go left*/
    		if(turn==3)
    			{
    				printf("next=%d\n",next);
    				printf("dipla=%d\n",dipla);
    				col=col-1;
    				cur=array[row][col];
    				ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);	
    				ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);
    				next=array[row][col-1];
    				dipla=array[row+1][col];
    				facing_wall(A,next,dipla);	
    			}
    
    
    facing_wall(A,next,dipla);
    /*go up*/
    		if(turn==4)
    		{
    				printf("next=%d\n",next);
    				printf("dipla=%d\n",dipla);	
    				row=row-1;
    				cur=array[row][col];
    				ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);
    				ip=&cur;
    				printf("turns=%d\n",turn);
    				printf("array[%d][%d]=%d\n",row,col,*ip);
    				next=array[row-1][col];
    				dipla=array[row][col+1];
    				facing_wall(A,next,dipla);	
    		}
         scanf("%d",&j);
    	}
    	return;
    }
    
    
    
    /*stripse de3ia*/
    void turn_right(void)
    // Was: void turn_right(int turn)
    {	
     
    	turn=1+turn;
    	if(turn==5)
    	{
    		turn=1;
    	}
    
    
    return;
    }
    
    
    /*stripse aristera*/
    void turn_left(void)
    // Was: void turn_left(int turn)
    {	
     
    	turn=turn-1;
    	if(turn==0)
    	{
    		turn=4;
    	}
    return;
    }
    
    
    
    
    
    
    
    
    /*vrhkame se toixo ? */
    
    void facing_wall(int array[size][size],int next,int dipla)
    {	
    
    		if(next==1 || dipla==0)
    			{
    			turn_right(turn);
    			printf("koitame de3ia\n");
    			}
    		else if(next==0|| dipla==0)
    			{
    			turn_right(turn);
    			printf("koitame de3ia\n");
    			}
    		else if(next==1 && dipla==1)
    			{
    			turn_left(turn);
    			printf("aristera\n");
    			}
    
    return;
    }

  5. #5
    Registered User sELigkari's Avatar
    Join Date
    May 2007
    Location
    Greece
    Posts
    4
    After doing what you said the compiler(visual c++) printed this message:

    Compiling...
    print2.c
    D:\Documents and Settings\m_a_p\Desktop\hy150\print2.c(277) : warning C4087: 'turn_right' : declared with 'void' parameter list
    D:\Documents and Settings\m_a_p\Desktop\hy150\print2.c(282) : warning C4087: 'turn_right' : declared with 'void' parameter list
    D:\Documents and Settings\m_a_p\Desktop\hy150\print2.c(287) : warning C4087: 'turn_left' : declared with 'void' parameter list

    print2.obj - 0 error(s), 3 warning(s)

    Besides hat it still does not change row.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    the error is pretty straightforward. its saying you have 2 functions "turn_right" and "turn_left" that take zero arguments but your passing more than zero arguments to it. i havent been following this thread or even looked at the code so i dont know how you want to change your function or logic.

  7. #7
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    you have a void function with a return satement.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  8. #8
    Registered User sELigkari's Avatar
    Join Date
    May 2007
    Location
    Greece
    Posts
    4
    Thanx to all of you for your time...I finally found out my mistakes and everything is right...I'll post the code later just if a noob like me want some help...

  9. #9
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    you have a void function with a return satement.
    you can use "return;" in void functions

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    But unlike in non-void functions, return statements in void functions are optional. You don't have to put them in. (Unless you want to return from some point in the code other than at the end of the function.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  2. Having trouble solving maze.
    By eurus in forum C Programming
    Replies: 3
    Last Post: 02-17-2006, 01:52 AM
  3. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  4. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 02:04 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21