Compiler error i dont understand

This is a discussion on Compiler error i dont understand within the C Programming forums, part of the General Programming Boards category; Ok so i'm now writing a program which has a 5 x 5 grid. The starting point is at [0,0] ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    79

    Compiler error i dont understand

    Ok so i'm now writing a program which has a 5 x 5 grid. The starting point is at [0,0] and the finish point is somewhere on the grid. The point of the program is to find the finish point and plot route from 0,0 to the finish point

    here is the code

    Code:
    #include<stdio.h>
    #include<string.h>
    
    #define SQ_GRID 5
    int Grid[SQ_GRID][SQ_GRID];
    int finishYCord = 0;
    int finishXCord = 0;
    int startYCord = 0;
    int startXCord = 0;
    
    
    //takes starting point and plants it on the grid.
    
    void plotRoute(){
    	
    	if(startYCord > finishYCord){
    
    		while(startYCord > finishYCord){
    			moveDown();	
    			}
    		}
    
    	else{
    
    		while(startYCord < finishYCord){
    		moveUp();
    		}
    	       }		
    }
    
    
    void moveDown(){
    	 startYCord--;
    	printf("[%d, %d] ", startYCord,startXCord);
    	
    	
    	}
    
     moveUp(){
    	startYCord++;
    	printf("[%d, %d] ", startYCord,startXCord);
    	
    	}
    	
    		
    
    void startingPoint(int yaxis, int xaxis)
    {
    	Grid[yaxis][xaxis] = 1;
    }
    
    void finishingPoint(int fYAxis, int fXAxis)
    {
    	Grid [fYAxis][fXAxis] = 2;
    	printf("GRID [%d][%d] Contains %d\n",fYAxis,fXAxis,Grid[fYAxis][fXAxis]);
    }
    
    void printGrid(){
    	int k;
    	int l;
    	for(k=0;k<SQ_GRID;k++){
    		for(l=0;l<SQ_GRID;l++){
    			
    			printf("GRID[%d][%d]now contains %d\n",k,l,Grid[k][l]);
    		}
    	}
    }
    	
    
    void fillArr(){
    	int k;
    	int l;
    	for(k=0;k<SQ_GRID;k++){
    		for(l=0;l<SQ_GRID;l++){
    			Grid[k][l] == 0;
    			printf("GRID[%d][%d]now contains %d\n",k,l,Grid[k][l]);
    		}
    	}
    	
    }
    
    void findFinish(){
    	int i;
    	int fFlagFound = 0;
    	int j;
    	for(i = 0; i < SQ_GRID; i++){
    		for(j = 0; j < SQ_GRID; j++){
    			if(Grid[i][j] == 2){
    
    				finishYCord = i;
    				finishXCord = j;
    				printf("\n\nFound finish in Grid [%d][%d]\n",finishYCord,finishXCord);
    				fFlagFound++;
    				}
    		}
    	}
    
    	if(fFlagFound == 0){
    		printf("Flag Not Found!\n");
    		}
    
    
    		
    }
    
    int main(){
    	startYCord= 0;
    	startXCord =0;
    	fillArr();
    	
    	finishingPoint(4,3);
    	printGrid();
    	
    	findFinish();
    	plotRoute();
    	return 0;
    }
    keeps giving me this compile error

    grid.c:32: error:conflicting types for moveDown
    grid.c:19: error: Previous implicit declaration of moveDown was here

    I had it running before but the code didnt work properly. After i changed it i get this.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You are calling "moveDown" before you define the function, which means that the compiler "guesses" what the function looks like, and then decides "Huh, that's not what I expected".

    Either move the function up above the call, or declare a prototype.

    And enable warnings in your compiler, so that the compiler tells you that there is a missing prototype.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    79
    Thnaks thats sorted it! Any ideas how i could build on this program to make it more advanced?

    I was thinking about trying to do something to include diagionals in a gird. But algorithms are not my strong point. Even if by other peples standards it would be a very easy algorithm

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,182
    You should learn to indent first: http://cpwiki.sf.net/User:Elysia/Indentation
    And then you could start giving all functions an explicit return type.
    Then you could get rid of those nasty global variables.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  5. #5
    Aia
    Aia is offline
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    Quote Originally Posted by mushy View Post
    ... Any ideas how i could build on this program to make it more advanced?
    Quote Originally Posted by Elysia View Post
    You should learn to indent first: http://cpwiki.sf.net/User:Elysia/Indentation
    And then you could start giving all functions an explicit return type.
    Then you could get rid of those nasty global variables.
    It tickles me that the more basic you get the more advanced the code becomes.
    Last edited by Aia; 02-01-2008 at 04:27 PM. Reason: Not important

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    79
    i appreciate your help and all elysia. However i'd appreciate if you would take that snobby attitude out of your replys. Yea your the programming master, way better than me . But perhaps if you want, we can discuss quantum mechanics or play a game of checkers of which i was the best player in my country for two years. Mabye we can talk about nuclear fusion or how neutron stars are produced.

    You see, your life if programming. Its all you have. Me i have a full time job, and in my spare time when im not training mma 4 times a week, i learn about other things. However if you were to ask me about the countless things im better than you at, i'd tell you in a polite way and give you the respect you deserve. I think you need to adjust your attitude and rethink your outlook on life.

    so to answer your question. My indentation is fine. Its readable your just being a picky for no reason other than to give a sarcastic answer to a question which you realised was asking for something else.

    I realise by having a go at you, im ruining my chances of anyone else ever helping me on here again. But if feel like that i dont want their help, because anyone who holds you in high regard clearly isnt worth knowing.

    Not that anything i say will have an effect on you. After all what do you expect from a pig but a runt!

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,182
    Quote Originally Posted by mushy View Post
    i appreciate your help and all elysia. However i'd appreciate if you would take that snobby attitude out of your replys. Yea your the programming master, way better than me . But perhaps if you want, we can discuss quantum mechanics or play a game of checkers of which i was the best player in my country for two years. Mabye we can talk about nuclear fusion or how neutron stars are produced.
    You asked for suggestions, I gave you some.

    You see, your life if programming. Its all you have.
    That's not true. I may be a programming "master", but that's because it's fun and I have lots of experience. Of course I do other things as well.

    However if you were to ask me about the countless things im better than you at, i'd tell you in a polite way and give you the respect you deserve. I think you need to adjust your attitude and rethink your outlook on life.
    That's so funny because you really have no idea who I am.
    I should politely say that it is not good to guess. I don't ask what you do, you don't ask what I do and we do not guess, foremost of all!
    I gave you suggestions.
    You don't like them? Then you can politely decline. I can't force you.

    so to answer your question. My indentation is fine. Its readable your just being a picky for no reason other than to give a sarcastic answer to a question which you realised was asking for something else.
    It's not. Some places, it's a mess. Ask anyone at the board and they'll tell you the same.
    Indentation is not a toy. It's a way to make your less prone to bugs and more readable to others. It's just as important as writing safe code.

    I realise by having a go at you, im ruining my chances of anyone else ever helping me on here again. But if feel like that i dont want their help, because anyone who holds you in high regard clearly isnt worth knowing.
    Careful here. That's big words.
    If you are unhappy about one individual, don't make everyone an enemy to you.

    Not that anything i say will have an effect on you. After all what do you expect from a pig but a runt!
    So what we get from helping you is rude remarks? Perhaps you should go try to teach yourself and we stop helping you.

    I have helped countless others. Many like you. Many have expressed thanks for my and others help. Why should you be an exception? I'm open to listening to what other people think and know, and you should too.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't always agree with Elysia, nor do I mind other people disagreeing [and we certainly don't have exactly the same rules about indentation style], but I do agree that indentation should be consistent and that it's part of how you make your code readable to another person.

    Your code happens to be fairly inconsistent: The openign bracket for functions is sometimes on the same line as the function, and sometimes not. End braces for loops and if-statements are a bit hit-and-miss about whether the line up with anything at all, never mind lining up with the "thing" they belong to.

    And the fucntion "moveup" doesn't have a return type declaration.

    Using global variables is seen as quite a bad thing by most people [although we all do sometimes - but the coding style at work almost requires permission from the Pope to get a global variable in the code]. In this particular case, there is no particular good reason to do so - you could quite easily use local variables and pass arguments from one function to another.

    No I don't know that much about quantum mechanics, but I probably know more about the fishes in the Family of Loricariidae than most people on this forum [although I don't do that for a living]. Nor can I play checkers, I'd probably loose even against a 5-year old, because it's a game I have never learnt [I could probably learn it, but it's not a traditonal game in Sweden where I grew up, and I'm not sure it is played regularly in England where I live, so I don't quite know who I would ask about it].

    We all know different things, and that's often helpful on a forum like this, because that's how you learn more about things. If we all knew the same thing, then we wouldn't have anything to discuss, and no hope in learning new things from others.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    >Yea your the programming master, way better than me .
    You do know that's just a signature, right? Not directed at you in particular.

  10. #10
    Aia
    Aia is offline
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    Quote Originally Posted by robwhit View Post
    >Yea your the programming master, way better than me .
    You do know that's just a signature, right? Not directed at you in particular.
    Yeah, a cheesy self promotion. Oops! I did say that aloud, didn't I?

  11. #11
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Here's something that does something that you seem to be looking for (going from point A to B if there are no obstacles).

    It treats X and Y axis separately and the strategy for both is the same and very simple (implemented in approach): if value and target are not equal increment or decrement by one to make it closer to the target.

    Note the use of function arguments over global variables.

    Code:
    #include<stdio.h>
    
    int approach(int from, int to)
    {
        int newPos = from;
        if (from < to) {
            ++newPos;
        }
        else if (to < from) {
            --newPos;
        }
        return newPos;
    }
    
    void plotRoute(int startX, int startY, int endX, int endY)
    {
        printf("From [&#37;d, %d] to [%d, %d]\n", startX, startY, endX, endY);
        printf("[%d, %d]\n", startX, startY);
        while (startX != endX || startY != endY) {
            startX = approach(startX, endX);
            startY = approach(startY, endY);
            printf("[%d, %d]\n", startX, startY);
        }
    }
    
    int main()
    {
        plotRoute(0, 0, 4, 3);
    }
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vc++ or my old compiler.
    By epidemic in forum Windows Programming
    Replies: 6
    Last Post: 07-10-2008, 03:22 PM
  2. OpenScript2.0 Compiler
    By jverkoey in forum C++ Programming
    Replies: 3
    Last Post: 10-30-2003, 12:52 PM
  3. Compiler Design... Anyone That Can Help!
    By ComputerNerd888 in forum C++ Programming
    Replies: 3
    Last Post: 09-27-2003, 09:48 AM
  4. Comile problem using latest Dev C++ Compiler
    By shiny_dico_ball in forum C++ Programming
    Replies: 6
    Last Post: 06-06-2003, 05:32 PM
  5. Can't compile on the other compiler
    By AProg in forum C Programming
    Replies: 8
    Last Post: 05-25-2003, 07:55 AM

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