feat: Initial commit
This commit is contained in:
53
Laboratorio 8/Esercizio 3/Asset.c
Normal file
53
Laboratorio 8/Esercizio 3/Asset.c
Normal file
@@ -0,0 +1,53 @@
|
||||
// Laboratorio 8 - Esercizio 3 - Asset.c
|
||||
// Matteo Schiff - s295565
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "Asset.h"
|
||||
#include "ExrateBST.h"
|
||||
|
||||
struct asset
|
||||
{
|
||||
char titolo[STR_LEN];
|
||||
ExrateBST exrates;
|
||||
};
|
||||
|
||||
Asset AssetCreate() {
|
||||
Asset a = malloc(sizeof(*a));
|
||||
a->exrates = ExrateBSTCreate();
|
||||
return a;
|
||||
}
|
||||
|
||||
void AssetFree(Asset a) {
|
||||
ExrateBSTFree(a->exrates);
|
||||
free(a);
|
||||
}
|
||||
|
||||
int AssetCompare(Asset a, Asset b) {
|
||||
return strcmp(a->titolo, b->titolo);
|
||||
}
|
||||
|
||||
char * AssetTitle(Asset a) {
|
||||
return a->titolo;
|
||||
}
|
||||
|
||||
ExrateBST AssetGetExrates(Asset a) {
|
||||
return a->exrates;
|
||||
}
|
||||
|
||||
Asset AssetRead(FILE *fp) {
|
||||
Asset n = AssetCreate();
|
||||
Exrate je;
|
||||
int Nitems;
|
||||
|
||||
fscanf(fp, " %s %d",n->titolo, &Nitems);
|
||||
for (int i = 0; i < Nitems; i++) {
|
||||
ExrateRead(&je, fp);
|
||||
ExrateBSTInsert(n->exrates, je);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void AssetPrint(Asset a) {
|
||||
printf(" - %s\n", a->titolo);
|
||||
}
|
||||
Reference in New Issue
Block a user