Reputation: 13
the main.c contains a global variable called cell2VoltageUV
which is given a value by function:
updateMeasurements();
this function is also located inside the main.c but not in the main function.
whenever I try to print the cell2VoltageUV
using a function in another .c file which also has a .h header file, I get the error:
'cell2VoltageUV' undeclared (first use in this function)
if i just do printf(cell2VoltageUV);
in the main function i get the correct value but if the same printf(cell2VoltageUV);
is located in another .c file function i get the error.
how do I get the correct value inside of the function I'm making?
ps. this is my first post here and I'm relatively new to c programming (Arduino experience only), this project I'm working on already has a lot of functions built-in and I'm trying to add more features.
Upvotes: 0
Views: 634
Reputation: 67979
lets say that your variable is of type int;
int cell2VoltageU;
Then in any other file you use this variable you must have
extern int cell2VoltageU;
Upvotes: 1