feat: Initial commit
This commit is contained in:
37
Laboratorio 8/Esercizio 2/Item.c
Normal file
37
Laboratorio 8/Esercizio 2/Item.c
Normal file
@@ -0,0 +1,37 @@
|
||||
// Laboratorio 8 - Esercizio 2 - Item.c
|
||||
// Matteo Schiff - s295565
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Item.h"
|
||||
|
||||
Item ITEMcreate(char *name, char *subnet) {
|
||||
Item t;
|
||||
strncpy(t.name, name, MAX_STR+1);
|
||||
strncpy(t.subnet, subnet, MAX_STR+1);
|
||||
return t;
|
||||
}
|
||||
|
||||
Item ITEMread(FILE * fp) {
|
||||
Item item;
|
||||
fscanf(fp, " %s %s", item.name, item.subnet);
|
||||
return item;
|
||||
}
|
||||
|
||||
Item ITEMnull() {
|
||||
Item t;
|
||||
strcpy(t.name, "");
|
||||
strcpy(t.subnet, "");
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
static int compareItem(const void *a, const void *b) {
|
||||
return strcmp((*(Item*)a).name, (*(Item*)b).name);
|
||||
}
|
||||
|
||||
void ITEMsort(Item *v, int N) {
|
||||
qsort(v, N, sizeof(Item), compareItem);
|
||||
}
|
||||
Reference in New Issue
Block a user