-
Notifications
You must be signed in to change notification settings - Fork 0
/
lecarro.c
79 lines (68 loc) · 1.64 KB
/
lecarro.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/******************************************************************************
* File Name: lecarro.c
* Author: João Rodrigues, Sara Vieira
* Revision: v1.0
* NAME
* Projeto-Gestor de Parque
* SYNOPSIS
* #include <stdlib.h>
* #include <stdio.h>
*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "parque.h"
/******************************************************************************
* lefilecarro()
*
* Arguments: FILE, double pointer to car
* Returns: Empty Park
*
* Description: Leitura de instruções do ficheiro
*
*****************************************************************************/
int lefilecarro(FILE *fp, car** new)
{
int x, y, z;
char as;
int ta = 0;
char id[5];
if( fscanf(fp, "%s", id) != 1)
return 0;
(*new) = (car*) malloc(sizeof(car));
if(fscanf(fp, "%d %c", &ta, &as) != 2)
exit(0);
if(fscanf(fp, "%d %d %d\n", &x, &y, &z) == 3)
{
(*new)->x = x;
(*new)->y = y;
(*new)->z = z;
}
else
{
(*new)->x = -1;
(*new)->y = -1;
(*new)->z = -1;
}
strcpy((*new)->id, id);
(*new)->access = as;
(*new)->ta = ta;
(*new)->tb = ta;
return 1;
}
/******************************************************************************
* vem_depois()
*
* Arguments: Item 1, Item 2
* Returns: 1 se c1->ta > c2->ta
*
* Description: Função de comparação para a lista de espera
*
*****************************************************************************/
int vem_depois(Item c1, Item c2)
{
if(((car*)c1)->ta > ((car*)c2)->ta)
return 1;
else
return 0;
}