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);
}
}
#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
}
I may have mixed in some C++, sorry. I tried to keep it as C as a I could.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With