-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValue.c
More file actions
60 lines (56 loc) · 1.39 KB
/
Copy pathValue.c
File metadata and controls
60 lines (56 loc) · 1.39 KB
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
#include "Value.h"
Value_t *ValueConstruct(int valueIndex, char *valueName)
{
Value_t *newValue = (Value_t *)malloc(sizeof(Value_t));
if(newValue == NULL)
{
printf("Not enough memory");
exit(0);
}
newValue->valueIndex = valueIndex;
strcpy(newValue->valueName, valueName);
newValue->next = NULL;
return newValue;
}
Value_t *getValue(Value_t **startValue, char *valueName)
{
if(*startValue == NULL)
{
*startValue = ValueConstruct(0, valueName);
return *startValue;
}
Value_t *currentValue = *startValue;
Value_t *prevValue = NULL;
while(currentValue != NULL)
{
if(strcmp(currentValue->valueName, valueName) == 0)
{
return currentValue;
}
prevValue = currentValue;
currentValue = currentValue->next;
}
prevValue->next = ValueConstruct(prevValue->valueIndex+1, valueName);
return prevValue->next;
}
int getValueSize(Value_t *startValue)
{
int valueSize = 0;
Value_t *currentValue = startValue;
while(currentValue != NULL)
{
valueSize++;
currentValue = currentValue->next;
}
return valueSize;
}
void printValue(Value_t *startValue)
{
Value_t *currentValue = startValue;
while(currentValue != NULL)
{
printf("%s ", currentValue->valueName);
currentValue = currentValue->next;
}
printf("\n");
}