37 lines
700 B
C
37 lines
700 B
C
// 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);
|
|
} |