I'm trying to write a bookstore program, and I'm getting an error saying "multiple definition" in my source code file at my function implementation.
Here is my Book.c file:
#include "Book.h"
void scanBook(book_t* bk) //error here
{
//implementation here
}
Here is my Book.h file:
#pragma once
#include <stdio.h>
typedef char* str;
typedef enum Genre {Education, Business, Novel} genre_t;
typedef struct Book{
str ISBN;
str title;
str author;
float price;
int quantity;
genre_t genre;
} book_t;
void scanBook(book_t* bk);
And here is my main.c file:
#include "Book.h"
#include "Book.c"
int main()
{
return 0;
}
The error occurs at the scanBook function in Book.c but I don't know why, since I included the header file as well as #pragma once, and in the header file I declared the function. It says multiple definition of 'scanBook' and obj\Debug\Book.o .... first defined here.
Any help or clarification would be greatly appreciated!
Don’t do:
#include “Book.c"
in your main.c file.