定义用C使用#define路径 [英] Defining path using #define in C
本文介绍了定义用C使用#define路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要定义这样的路径:
的#define PATH / ABC / XYZ / LMN
这PATH是具有文件foo1,foo2的,foo3 ... foo115目录。
我如何使用这个的#define,在打开叫开foo1,foo2的,... foo115?
我想基本上做到这一点使用的指令:
FD =打开(/ ABC / XYZ / LMN / foo1,O_RDONLY);
解决方案
的#define PATH/ ABC / XYZ / LMNINT主(INT ARGC,字符** argv的)
{
烧焦file2open [256];
INT I; 对于(i = 1; I< = 115;我++)
{
sprintf的(file2open,%sfoo%D的路,我);
FD =开(file2open,O_RDONLY)
......
关闭(FD);
}}
I want to define a path like this:
#define PATH /abc/xyz/lmn
This PATH is a directory which has files foo1, foo2, foo3, ... foo115.
How can I use this #define in the "open" call to open foo1, foo2, ... foo115 ?
I want to basically do this using the directive:
fd = open("/abc/xyz/lmn/foo1", O_RDONLY);
解决方案
#define PATH "/abc/xyz/lmn"
int main (int argc, char **argv)
{
char file2open[256];
int i;
for (i = 1; i <= 115; i++)
{
sprintf (file2open, "%sfoo%d", PATH, i);
fd = open (file2open, O_RDONLY)
......
close (fd);
}
}
这篇关于定义用C使用#define路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文