I have 3 files. variables.h, variables.c, and dictionary_test.c. How would I use my variables.c to get information from variables.h and dictionary_test.c? I'm not supposed to touch the variables.h and dictionary_test.c. I gotta do all the work in variables.c. This is the variables.h.
#define MAX_VARIABLE_LENGTH 15
/* Set the variable with the specified name to the specified value.
* If there is not a variable with that name in the dictionary,
* add one. */
void set_variable (const char* name, double value);
/* Return the value of the variable with the specified name.
* If variable does not exist, add it to the dictionary
* with a default value of 0.0, and return that value. */
double variable_value(const char* name);
/* Display the names and values of all variables in the dictionary. */
void display_variables();
This is the dictionary_test.c.
#include <stdio.h>
#include "variables.h"
void verify (double result, double expected_value)
{
if (result != expected_value)
{
printf ("Incorrect result. Should be %8.4f\n\n", expected_value);
}
}
int main()
{
double result;
printf ("Starting dictionary test\n\n");
set_variable("A1", 1.0);
set_variable("A2", 2.0);
set_variable("A3_3333", 3.3333);
result = variable_value("A1");
printf ("A1 is %8.4f.\n", result);
verify(result, 1.0);
result = variable_value("A2");
printf ("A2 is %8.4f.\n", result);
verify(result, 2.0);
result = variable_value("A3_3333");
printf ("A3_333 is %8.4f\n", result);
verify(result, 3.3333);
set_variable("A long variable", -1.0);
result = variable_value("A long variable");
printf ("A long variable is %8.4f\n", result);
verify(result, -1.0);
result = variable_value("Unset Variable ");
printf ("Unset Variable is %8.4f\n", result);
verify(result, 0.0);
printf ("\n");
printf ("All variables:\n");
display_variables();
printf ("Dictionary test complete\n");
getchar();
return 0;
}
And this is the start to variables.c.
#include <stdio.h>
int main()
{
return 0;
}
I was given the variables.h and dictionary_test.c. and it won't even compile and I can't even change it. Here are the errors I get.
gcc -Wall *.c
/tmp/cceDui0k.o: In function `main':
dictionary_test.c:(.text+0x60): undefined reference to `set_variable'
dictionary_test.c:(.text+0x7d): undefined reference to `set_variable'
dictionary_test.c:(.text+0x9a): undefined reference to `set_variable'
dictionary_test.c:(.text+0xa4): undefined reference to `variable_value'
dictionary_test.c:(.text+0xf1): undefined reference to `variable_value'
dictionary_test.c:(.text+0x149): undefined reference to `variable_value'
dictionary_test.c:(.text+0x1b4): undefined reference to `set_variable'
dictionary_test.c:(.text+0x1be): undefined reference to `variable_value'
dictionary_test.c:(.text+0x216): undefined reference to `variable_value'
dictionary_test.c:(.text+0x273): undefined reference to `display_variables'
collect2: ld returned 1 exit status
Any ideas and help would be greatly appreciated.