Archived
1
0
Fork 0
This repository has been archived on 2023-11-10. You can view files and clone it, but cannot push or open issues or pull requests.
SLOTH/src/variables/variable.c

27 lines
No EOL
702 B
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "variable.h"
/* creates a new variable and returns it */
struct Variable* make_variable(char* id, struct Value* value) {
/* allocate space */
struct Variable* var = (struct Variable*) malloc(sizeof(struct Variable));
/* set properties */
strcpy(var->id, id);
var->value = value;
/* return new variable */
return var;
}
void set_value(struct Variable* var, struct Value* value) {
if (!var) { fprintf(stderr, "Error: Invalid Variable\n"); return; }
var->value = value;
}
struct Value* get_value(struct Variable* var) {
if (!var) { fprintf(stderr, "Error: Invalid Variable\n"); return 0; }
return var->value;
}