-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vartab.c
59 lines (53 loc) · 1.12 KB
/
Vartab.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
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include <math.h>
#include "UGL.H"
typedef struct tagVARLIST VARLIST;
typedef struct tagVARLIST
{
char Name[MAX];
double Value;
VARLIST *Next;
};
VARLIST *VarTable = NULL;
void SetValue( char *Name, double Value )
{
VARLIST **ptr = &VarTable;
while (*ptr != NULL)
{
if (strcmp((*ptr)->Name, Name) == 0)
{
(*ptr)->Value = Value;
return;
}
else
ptr = &(*ptr)->Next;
}
if ((*ptr = malloc(sizeof(VARLIST))) == NULL)
Error("Nor enuogh mem for new var");
strncpy((*ptr)->Name, Name, MAX - 1);
(*ptr)->Value = Value;
(*ptr)->Next = NULL;
}
double GetValue( char *Name )
{
VARLIST **ptr = &VarTable;
while (*ptr != NULL)
{
if (strcmp((*ptr)->Name, Name) == 0)
return (*ptr)->Value;
else
ptr = &(*ptr)->Next;
}
return 0;
}
void DisplayVarTable(void)
{
VARLIST **ptr = &VarTable;
while (*ptr != NULL)
{
printf("%s : %llf ", (*ptr)->Name, (*ptr)->Value);
ptr = &(*ptr)->Next;
}
}