Specifica dei tipi di dati

Specifica degli operatori

Implementazione: file libro.h

typedef struct lib
{
	char autore[26];
	char titolo[53];
	char editore[26];
	int anno;
} libro;

libro creaLibro(char *aut, char *tit, char *ed, int anno);
char *autore(libro l);
char *titolo(libro l);
char editore(libro l);
int anno(libro l);

File libro.c

#include "libro.h"

libro creaLibro(char *aut, char *tit, char *ed, int anno)
{
	libro l;
	strcpy(l.autore, aut);
	strcpy(l.titolo, tit);
	strcpy(l.editore, ed);
	l.anno = an;
	return l;
}

char *autore(libro L)
{
	char *aut;
	aut = calloc(26, sizeof(char));
	strcpy(aut, L.autore);
	return aut;
}

char *titolo(libro L)
{
	char *tit;
	tit = calloc(53, sizeof(char));
	strcpy(tit, L.titolo);
	return tit;
}

char *editore(libro L)
{
	char *ed;
	ed = calloc(26, sizeof(char));
	strcpy(ed, L.editore);
	return ed;
}

int anno(libro L)
{
	return L.anno;
}