Hej, mam listę, która może przyjmować za argumenty kilka rzeczy(int, struct film, struct person, ...)
Tyle że struct film zawiera w sobie listę intów.
Jak zrobić to tak żeby struct film widział struct list_handler i odwrotnie?
Coś jak z funkcjami i deklarowaniem ich istnienia nad mainem
Całość kodu, ale trochę tego jest:
#include <stdio.h>
#include <stdlib.h>
// === DATA SECTION ===
typedef enum list_element_type
{
integer, catalogue, person, film, fillable
}LIST_ELEMENT_TYPE;
typedef enum fillable_value_type
{
word, number
}FILLABLE_VALUE_TYPE;
//problem: film needs list_handler to int/string list, list needs film for a possible union option in element data
typedef struct film
{
int id;
LIST_HANDLER *fillable_list_handler;//TODO: make sure its allocated properly in allocate_film()
}FILM;
typedef struct person
{
int id;
LIST_HANDLER *fillable_list_handler;//TODO: make sure its allocated properly in allocate_person()
LIST_HANDLER *borrowed_films_list_handler;//TODO: allocate with matching type
}PERSON;
typedef struct catalogue
{
int id;
LIST_HANDLER *fillable_list_handler;//TODO: make sure its allocated properly in allocate_catalogue()
LIST_HANDLER *films_list_handler;//TODO: allocate with matching type
}CATALOGUE;
typedef union list_element_data
{
int i;//probably only used for adresses of borrowed films, films in catalogues
FILM *film;
PERSON *person;
CATALOGUE *catalogue;
FILLABLE *fillable;
}LIST_ELEMENT_DATA;
typedef struct list_element
{
struct list_element *next;
struct list_element *previous;
LIST_ELEMENT_DATA *data;
}LIST_ELEMENT;
typedef struct list_handler
{
LIST_ELEMENT_TYPE element_type;//elements in the list will be of this type
int count;//number of elements in the list. Counted after adding/removing from list
LIST_ELEMENT *beg;
LIST_ELEMENT *last;
}LIST_HANDLER;
typedef struct fillable
{
enum fillable_value_type;//word/number
FILLABLE_VALUE *value;
int min_value, max_value;//for checking if user input is good. For strings this means the length
char name[25];//for displaying to the user what he is changing/adding
//int id; //probably not needed - we can make the user type whole name instead
}FILLABLE;
typedef union fillable_value
{
char *word;
int number;
}FILLABLE_VALUE;
// === FUNCTIONS ===
//these contain all the data for whats's in a film/person/catalogue;
//FIXME: for better code expandability better to keep this data in some structs and use one function to allocate a new struct element.
FILM* allocate_new_film();
PERSON* allocate_new_person();
CATALOGUE* allocate_new_catalogue();
//list operations
//TOADD: add those that you need as you go
void push_back(LIST_HANDLER *h, LIST_ELEMENT *e);
//moving data around aka main functions
void add_new(LIST_HANDLER *h);//checks what kind of data is stored in h and adds an element of that data
void modify(LIST_ELEMENT_DATA *data, enum list_element_type);//lets user choose one of the fillables(f.ex. by name) and modifies the given fillable
void remove(LIST_HANDLER *h);//ask user for id of item to remove and remove this item from the list. Also, if item was of film type, remove list elements with its value in lists in people, catalogues
//user communication
//TODO:add an option to give strings in args. Then only print fillables with names==those_strings
void print_list_element(LIST_ELEMENT e);//prints all fillables' names and values
void print_list(LIST_HANDLER h);
//sorting
//TODO: add sorting
//files
//TODO: add files
//additional functions:
//TODO: add as we go
int main()
{
//initialize the necessary data
LIST_HANDLER *films_list_handler = (LIST_HANDLER*)malloc(sizeof(LIST_HANDLER));
LIST_HANDLER *people_list_handler = (LIST_HANDLER*)malloc(sizeof(LIST_HANDLER));
LIST_HANDLER *catalogues_list_handler = (LIST_HANDLER*)malloc(sizeof(LIST_HANDLER));
films_list_handler->count=0;
films_list_handler->beg=NULL;
films_list_handler->last=NULL;
films_list_handler->element_type=film;
return 0;
}