Thread: Error : redefinition; different basic types

  1. #1
    Registered User
    Join Date
    Nov 2011
    Location
    Orlando, Florida, United States
    Posts
    2

    Error : redefinition; different basic types

    I am trying to save binary information. But this is the first time I am really using it. Compiler just really hates my function... :/

    code follows .c source attached

    Code:
    /*Sean 'Prime'
    Exam 4
    11/17/2011
    This program plays the battleship game. It allows the player to choose where to hide their ships,
    the AI hide ships. The game is played and the AI hunts the players ships, through randomly chosen 
    coordinates.
    */
     
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <Windows.h>
    
    
    
    
    //================================
    void pause ();
    void clear ();
    void pauseNClear ();
    void printLogo ();
    int mainMenu ();
    void printGameLogo ();
    void loadHighScores (SCORE *high);
    //================================
    typedef struct {
        char names[10];
        int scores[10];
    }SCORE;
    //================================
    int main (){
        int choice;
        SCORE high = {0,0};
    
    
    
    
        loadHighScores(&high);
        printLogo();
        do{
        choice = mainMenu();
    
    
        }while (choice != 3);
    
    
    
    
    pause();
    }
    
    void loadHighScores (SCORE *high){
        int start = 0;
        FILE *the_scores;
    
    
        the_scores = fopen ("BattleshipHighScores.bin", "rb+");
    
    
        if (the_scores == NULL){
            printf ("This did not work.\n");
            pauseNClear();
        }
    
    
        if (fread (&start,sizeof(int),1,the_scores) !=1){ /*check to see if there are high scores on start up*/
            rewind(the_scores);
            start = 1; /*if not lets put some in*/
            fwrite (&start,sizeof(start),1,the_scores);
            fwrite (&high, sizeof(sizeof(SCORE)),1,the_scores);
        }
        rewind(the_scores);
        fseek(the_scores,1,0);
        fread (&high,sizeof(SCORES),1,the_scores);
        
    }
    here is the error report:
    Code:
    1>------ Build started: Project: battleship, Configuration: Debug Win32 ------
    1>  exam4.c
    1>d:\dropbox\school\c programming\battleship\battleship\exam4.c(22): error C2143: syntax error : missing ')' before '*'
    1>d:\dropbox\school\c programming\battleship\battleship\exam4.c(22): error C2143: syntax error : missing '{' before '*'
    1>d:\dropbox\school\c programming\battleship\battleship\exam4.c(22): error C2059: syntax error : ')'
    1>d:\dropbox\school\c programming\battleship\battleship\exam4.c(34): warning C4013: 'loadHighScores' undefined; assuming extern returning int
    1>d:\dropbox\school\c programming\battleship\battleship\exam4.c(94): warning C4013: 'intScan' undefined; assuming extern returning int
    1>d:\dropbox\school\c programming\battleship\battleship\exam4.c(116): error C2371: 'loadHighScores' : redefinition; different basic types
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Attached Files Attached Files

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Try defining the SCORE struct before your function prototypes.
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    Registered User
    Join Date
    Nov 2011
    Location
    Orlando, Florida, United States
    Posts
    2
    AHHH IT WORKS!!!! +1 +1 +1 thanks I have been on that for over an hour!

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Sean'Prime' View Post
    AHHH IT WORKS!!!! +1 +1 +1 thanks I have been on that for over an hour!
    Just to give you a little more explaination...
    Suppose you are reading a book but the first chapter, introducing the characters and laying out the basic plot line was out of order... what happens when you start at chapter 2?

    C has the same problem. The compiler reads from the top of the source file down... it can't know about anything it hasn't seen yet, thus when it hits your function prototype using the SCORE struct as a parameter it's put into the "WTF??" stated and will make assumptions (usually wrong) about your code, or it will just bail and stop compiling.

    Since the compiler is a whole lot more stupid than we are, it falls to us to make sure it gets what it needs in the order it needs it.

    One other point... if you have functions that take no parameters you should prototype and define them like this...
    Code:
    int MyFunction (void)
    The (void) says "no parameters". The blank brackets () say "unknown parameters" and there are times when that distinction is important.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class Redefinition error
    By derder in forum C++ Programming
    Replies: 1
    Last Post: 11-06-2011, 08:55 PM
  2. Replies: 1
    Last Post: 11-15-2010, 11:14 AM
  3. Classes and redefinition; different basic types help
    By StealthRT in forum C++ Programming
    Replies: 3
    Last Post: 10-04-2009, 04:10 AM
  4. Replies: 6
    Last Post: 04-21-2009, 08:48 AM
  5. Redefinition Error
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2002, 04:11 PM

Tags for this Thread