Error 5 error C2371: 'score' : redefinition; different basic types c:\documents and s

This is a discussion on Error 5 error C2371: 'score' : redefinition; different basic types c:\documents and s within the C Programming forums, part of the General Programming Boards category; um..i split up a code into two .c files and one .h file and am getting the above mentioned error ...

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    6

    Error 5 error C2371: 'score' : redefinition; different basic types c:\documents and s

    um..i split up a code into two .c files and one .h file and am getting the above mentioned error in the title,it runs fine when it is not split up,could someone tell me what am doing wrong:

    driver.c file
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <time.h>
    #include "guessgame2.h"
    
    
    void play(int,int,int[],score,FILE *, score,FILE *);
    
    
    int main()
    {
        FILE *newfile, *read;
        score newscore;
        score oldscore;
        int allscores[3]={0};
        int number, guess;
        int correct;
    
    
        correct =1;
    
    
    
    
    srand(time(NULL));
    number = rand()%10+1;//%32767 + 1;
    
    
    
    
    
    
    
    
    
    
         printf("Welcome to the guessing game\n\n");
    
    
        if(read = fopen("gameinfo.txt","r"))          //read the previous scores from file
    	{
    
    
            fscanf(read,"%d %d %d", &oldscore.attempts, &oldscore.higher, &oldscore.lower);
            printf("\n\nPrevious high score.\n\n");
            printf("Attempts\t\t%d\n\nToo High\t\t%d\n\nToo Low\t\t\t%d",oldscore.attempts,oldscore.higher,oldscore.lower);
    
    
    	}
    
    
       play(guess,number, allscores, newscore, read,oldscore,newfile); //checks if number entered by user is higher or lower than the current number and also checks if the
                      																	//newscore is higher than the old score
    
    
       getch();
    
    
    
    
    
    
    return 0;
    }

    this is the guessgame2.c file

    Code:
    #include<conio.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<time.h>
    #include "driver.c"
    #include "guessgame2.h"
    
    
    
    
    
    
    
    
    void play(int guess,int number,int allscores[],score newscore,FILE *  read, score oldscores,FILE * newfile)   //function call
    {
    	      //points to the file that stores all number entered by the user
       int copy=0,prev;
            //open file for writing
    
    
    
    
    	do
       {
    
    
    
    
    	printf("Please enter your number\n");                                                                                 //outputs previous score by the user
       scanf("%d",&guess);
       system("CLR");
       printf("\n\n");
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
       allscores[0]++;
          if(guess < number)
           {
             printf("this is too low. Please retry\n\n");    //increments each time the number is lower than the computer's number
    
    
             allscores[1]++;
    
    
            }
            if(guess>number)
            {
                 printf("this is too high. Please retry\n\n");     //increments each time the number is higher than the computer's number
    
    
                 allscores[2]++;
            }
        }while(guess!=number);
        if(guess==number)
        {
    
    
          newscore.attempts = allscores[0];
          newscore.lower = allscores[1];           //assigns all the current scores to the newscore variables
          newscore.higher = allscores[2];
          printf("congrats you got it right\n\n");
          printf("Thank you for playing here is your score.\n\n");
          printf("Attempts\t\t%d\n\nToo High\t\t%d\n\nToo Low\t\t\t%d",newscore.attempts,newscore.higher,newscore.lower); //outputs the newscores
        }
    
    
    
    
    
    
         if(allscores[0]<=oldscores.attempts)
          {
    
    
    
    
              fclose(read);
              newfile=fopen("gameinfo.txt","w");            //writes the newscores to file
    
    
    
    
                fprintf(newfile,"%d ",newscore.attempts);
                fprintf(newfile,"%d ",newscore.higher);
                fprintf(newfile,"%d \n",newscore.lower);
          }
    
    
     }

    this is my guessgame2.h file

    Code:
    #define GUESSGAME2_H
    
    
    
    
    
    
    typedef struct
    {
            int attempts;
            int higher ;
            int lower;
    }score;

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    > #include "driver.c"
    Create a project which has TWO source files.

    Not a project with one source file including another source file.

    Since both .c files include guessgame2.h, which has BROKEN include guards, you end up with multiple declaration errors.


    > #define GUESSGAME2_H
    It goes like this
    Code:
    #ifndef GUESSGAME2_H
    #define GUESSGAME2_H
    
    // All the stuff which must be declared only once
    
    #endif
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2012
    Posts
    6
    so salem, should i take out #include 'guessgame2.h" out of driver.c? is that what you are saying?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    > so salem, should i take out #include 'guessgame2.h" out of driver.c? is that what you are saying?
    No, take this out
    #include "driver.c"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Oct 2012
    Posts
    6
    ok thanks that worked i just need one more thing figured out, am trying to get the program to print to a notepad file but am getting this error before the program runs and am guessing it has something to do with it: "Run-Time Check Failure #3 - The variable 'newfile' is being used without being initialized."

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    > "Run-Time Check Failure #3 - The variable 'newfile' is being used without being initialized."
    Yes, we know.

    You've been ignoring the fix for 3 days now.
    Dev Shed Forums - View Single Post - Run-Time Check Failure #3
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Oct 2012
    Posts
    6
    ok salem i will try to fix it, thanks for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error : redefinition; different basic types
    By Sean'Prime' in forum C Programming
    Replies: 3
    Last Post: 11-17-2011, 08:14 PM
  2. Replies: 1
    Last Post: 11-15-2010, 10: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

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