I'm trying to assign a value to my #define using a method that gets said value from a file.
I'm able to get the value from the file and return it to the main method. The define is able to call it and initialize it, but when another method uses said define, I get this error "initializer element is not constant"
I tried to set the method as const int, but I didn’t have any success. What can I do to fix this?
Code Example:
#define VALUE getValue()
int getValueFromFile(){
File *fp;
int value;
if((fp = fopen("configFile.txt","rt")) != NULL){
fscanf(fp,"value=%d\n",&value);
fclose(fp);
return value;
}else{
return -1;
}
int getValue(){
int value;
if((value=getValueFromFile()) != -1){
return value;
}else{
return 10;
}
Then when I try to use it like
static unsigned long int testValue = (unsigned long int) VALUE;
I get the error "initializer element is not constant"
Ok, so the #define is no good. I'm trying to use a global variable, but the error now changed to "error: variably modified ---- at file scope" The global variable are not static.
What should I do?