AnsweredAssumed Answered

How to #include a variable file name?

Question asked by Yaniv.Sapir on Jan 20, 2010
Latest reply on Jan 22, 2010 by Yaniv.Sapir

Hi,

 

My project consists of processing multiple data files, but only one at a given time. The data files have similar names with the "case number" changing. The code itself dependes on the specific data file I am using. Specifically, let's say I have a macro contains the case (data file) number:

 

// Cases are 200, 203, 209

#define CASE 200

 

Now, I need to #include the relevant data file and additional header and definition files that have the case number in their names.

 

#include "data_for_case_200.dat"

#include "definitions_200.h"

 

I tried to automate the selection of the correct file names by using the macro CASE in the #include directives. I tried various approaches. However the compiler keeps complaining that it expects a file name agter the #include directive. What I need is something like:

 

#define DATA_FILE data_for_case_##CASE##.dat

#include #DATA_FILE

 

My current solution is to use an #if CASE == XXX directive tree, for conditional compilation, but this is very non-flexible.

 

Any ideas?

 

Thaks,

Yaniv.

Outcomes