Hi All,
Let me explain the problem.
I have multiple include files as in class1.inc, class2.inc, class3.inc etc. Contents of an include file will be like
class1.inc
{
"john",
12,
68,
"steve",
12,
98,
"mat",
12,
95,
};
This will basically serve as a static array of structures. Here there are three field name(char*), age(int), avg(float).
In my program I want to assign the value of one of these file to a structure variable. My code goes like this
struct std_
{
char name[50];
int age;
float avg;
}
std_str, *std_ptr;
int main(int argc, char **argv)
{
if(!strcmp(argv[2],"class1")
{
static std_str obj[200] =
#include "class1.inc"
...
}
else if(!strcmp(argv[2],"class2")
{
...
}
return 0;
}
The above code will work fine. But what I want is
int main(int argc, char **argv)
{
char file[50];
/* I want to dynamically generate the include file name and include it */
strcat(file, argv[2]);
strcat(file, ".inc")
static std_str obj[200] =
#include file
return 0;
}
But unfortunately, the compilation fails, saying #include expects a file name.
Is there anyway to achieve this?
Thanks and Regards,
Ahamed.