-
Notifications
You must be signed in to change notification settings - Fork 0
/
fahrplanauskunft.c
64 lines (57 loc) · 1.59 KB
/
fahrplanauskunft.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "types.h"
#include "fahrplanauskunft.h"
//#include "debug.h"
#include "heap.h"
#include "prioritysearch.h"
int main(int argc, char *argv[])
{
// One parameter for input filename
programname = argv[0];
if(argc != 2)
{
printF1();
return EXIT_FAILURE;
}
// addresses to heap-root for both threads
heapnode **heapBeginn = (heapnode **)malloc(sizeof(heapnode *));
list **listRoot = (list **)malloc(sizeof(list *));
char *readIn = argv[1];
int count = load(readIn, listRoot);
station *startStation, *endStation;
//displaypath(listRoot);
if(count == 0) {
fprintf(stdout, "Datei enthält keine Stationen\n");
exit(EXIT_SUCCESS);
}
//buffer for defining source and destination halt
char buffer[BUFFERSIZE];
char *source;
char *destination;
fprintf(stdout, "Start: ");
fgets(buffer, BUFFERSIZE, stdin);
chomp(buffer);
source = trimTabsAndBlanks(buffer);
fprintf(stdout, "Ziel: ");
fgets(buffer, BUFFERSIZE, stdin);
chomp(buffer);
destination = trimTabsAndBlanks(buffer);
if(strcmp(source, destination) == 0)
{
fprintf(stderr, "Sie befinden sich bereits an der eingegebenen Station.\n");
exit(EXIT_SUCCESS);
}
else
{
startStation = searchHalt(source, listRoot);
endStation = searchHalt(destination, listRoot);
if(startStation == NULL || endStation == NULL) {
fprintf(stdout, "Mindestens eine Station ist nicht verfügbar!\n");
exit(EXIT_SUCCESS);
}
}
search(startStation, endStation, heapBeginn);
fprintf(stdout, "\nVerbindung\n-----------\n");
printStations(endStation);
fprintf(stdout, "Fahrtdauer: %i\n", endStation->lengthSum);
return EXIT_SUCCESS;
}