Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在C中使用#define定义路径_C_Linux_C Preprocessor - Fatal编程技术网

在C中使用#define定义路径

在C中使用#define定义路径,c,linux,c-preprocessor,C,Linux,C Preprocessor,我想定义这样的路径: #define PATH /abc/xyz/lmn 此路径是一个目录,其中包含文件foo1、foo2、foo3、。。。食品115 我如何使用这个#在“open”调用中定义来打开foo1、foo2。。。foo115 我想用指令基本上做到这一点: fd = open("/abc/xyz/lmn/foo1", O_RDONLY); #定义路径“/abc/xyz/lmn” int main(int argc,字符**argv) { char file2open[256]; in

我想定义这样的路径:

#define PATH /abc/xyz/lmn
此路径是一个目录,其中包含文件foo1、foo2、foo3、。。。食品115

我如何使用这个#在“open”调用中定义来打开foo1、foo2。。。foo115

我想用指令基本上做到这一点:

fd = open("/abc/xyz/lmn/foo1", O_RDONLY);
#定义路径“/abc/xyz/lmn”
int main(int argc,字符**argv)
{
char file2open[256];
int i;
对于(i=1;i
#定义路径)/some/PATH/to/foo/files”
对于(int i=0;1

我可能在一些C++中混了,对不起。我试图保持它为C,我可以。

< P>例如,打开<代码> Foo44可以做:

#define PATH  "/abc/xyz/lmn"
fd = open(PATH "/foo42", O_RDONLY);

既然您使用的是sprintf,那么const char*不是比define更好吗?我是老派(也许只是老了)而且#define是我的习惯-const char*也一样好:)下一个问题是,OP真的希望这是一个编译时常量吗?这条路径有可能改变吗?基于
我如何在“打开”呼叫打开foo1、foo2、…foo115?
我说不
#define PATH "/some/path/to/foo/files"

for (int i = 0; 1 < SomeNumberOfFiles; i++)
{
    char carray[256] = strcat(PATH, "foo");
    carray = strcat(carray, char(i));
    //Do something with the carray filename
}
#define PATH  "/abc/xyz/lmn"
fd = open(PATH "/foo42", O_RDONLY);