简体   繁体   中英

C error in linking library

I am begginer in C and I have a problem with linking .c and .h files into main.c

I tried to link it and it looks like this in main.c :

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "hangman.h"
#include "hangman.c"
#include <string.h>
#include <time.h>
#include <ctype.h>

    int main(void)
    {
    char secret[20];
    srand(time(NULL));
    getWord(secret);
    hangman(secret);
    return 0;
    }

and like this in .c file

#include <stdio.h>
#include <stdlib.h>
 #include <sys/stat.h>
#include <string.h>
#include "hangman.h"

int isWordGuessed(const char secret[], const char lettersGuessed[]){
int pom = 0;
int i,j;
for(i = 0; i < strlen(secret); i++){
    for (j= 0; j < strlen(lettersGuessed); j++)
    {
        if(secret[i] == lettersGuessed[j])
            pom = 1;
    }
    if(pom == 1){
        pom = 0;
    }
    else{
        return 0;
    }
  }
  return 1;
}

and like this in .h file

#define WORDLIST_FILENAME "words.txt"
int isWordGuessed(const char secret[], const char lettersGuessed[]);

Program just throws an exception. It tells me:

hangman.o: In function isWordGuessed': hangman.c:(.text+0x0): multiple definition of isWordGuessed' main.o:main.c:(.text+0x0): first defined here

#include "hangman.h"
#include "hangman.c"

Do not include .c source files in your program. The include directive will simply copy hangman.c in your main.c .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM