Ok, so i'm supposed to create this ADT structure and i'm having problems storing data into a function and printing it.
These are the three files I have:
#include "myBook.h"
#include <stdio.h>
#include <stdlib.h>
Book *createBook(char title, float price, int stock, char person)
{
Book *myBook;
myBook = (Book*) malloc(sizeof(Book));
(*myBook).bookName = title;
(*myBook).bookPrice = price;
(*myBook).bookStock = stock;
(*myBook).bookPerson = person;
return myBook;
}
void destroyBook(Book *myBook)
{
free (myBook);
}
void printBook(Book *myBook)
{
printf (*myBook).bookName;
printf (*myBook).bookPrice;
printf (*myBook).bookStock;
printf (*myBook).bookPerson;
}
int setName(Book *myBook, char title)
{
(*myBook).bookName = title;
}
int retrieveName(Book *myBook)
{
(*myBook).bookName;
}
int lendBook(Book *myBook, char person)
{
(*myBook).bookPerson = person;
}
int bookReturn(Book *myBook, int stock)
{
(*myBook).bookStock = stock;
}
int bookLentOut(Book *myBook)
{
if (*myBook).bookStock = 0
return FALSE;
else
return TRUE;
}
int bookSetPrice(Book *myBook, float price)
{
(*myBook).price = price;
}
int bookRetrievePrice(Book *myBook)
{
(*myBook).price;
}
#define TRUE 1
#define FALSE 0
typedef struct {
char bookName;
float bookPrice;
int bookStock;
char bookPerson;
} Book;
Book *createBook(char title, float price, int stock, char person);
void destroyBook(Book *myBook);
void printBook(Book *newBook);
int setName(Book *myBook, char title);
int retrieveName(Book *myBook);
int lendBook(Book *myBook, char person);
int bookReturn(Book *myBook, int stock);
int bookLentOut(Book *myBook);
int bookSetPrice(Book *myBook, float price);
int bookRetrievePrice(Book *myBook);
#include "myBook.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
FILE* pFile = NULL;
char filename[80];
char title[100];
float price;
int stock;
char person[100];
// asking the user to enter a filename, the file will read the conents
printf("Please enter a filename for input: ");
scanf("%s", &filename);
pFile = fopen(filename, "r");
if (pFile == NULL)
{
printf ("Error opening file!\n");
return -1;
}
while (!feof(pFile))
{
fgets(title, sizeof(title), pFile);
fscanf(pFile, "%f", &price);
fscanf(pFile, "%d", &stock);
fgets(person, sizeof(person), pFile);
fclose(pFile);
}
createBook(*title, price, stock, *person);
printBook();
destroyBook();
getch();
return 0;
}
This is the error i'm getting:
In function `main':
39 too few arguments to function `printBook'
40 too few arguments to function `destroyBook'
Can anyone help please?