Computer Science Canada concatenating Directories |
Author: | DtY [ Sat Aug 22, 2009 10:24 pm ] | ||||
Post subject: | concatenating Directories | ||||
If you have the directory 'a' with the file 'b' in it, it would be 'a/b' on Unix, but 'a\b' on Windows. In Pyhton, this could be solved by using os.path.join('a', 'b'), and this is what I came up for in C:
This works for what I currently need it for, however it has the downside that it only works with two constants. You can't use user input in any way, or any other variables. I also tried
However, the compiler (at least GCC) doesn't expand macros inside strings, which makes sense. Is there a better way to join directories? |
Author: | rdrake [ Sat Aug 22, 2009 11:11 pm ] |
Post subject: | RE:concatenating Directories |
People on the internets say in C you can just use a forward slash for everything and it's supposed to work properly on every platform. Are you just trying to open a file or are you doing something else? Source: here. |
Author: | DtY [ Sun Aug 23, 2009 11:20 am ] |
Post subject: | RE:concatenating Directories |
Thank you. That looks like what I need I'll be using fopen(), and SDL_loadBMP(), which I assume uses fopen() |
Author: | OneOffDriveByPoster [ Sun Aug 23, 2009 5:16 pm ] | ||
Post subject: | Re: concatenating Directories | ||
DtY @ Sat Aug 22, 2009 10:24 pm wrote:
However, the compiler (at least GCC) doesn't expand macros inside strings, which makes sense. It does not make sense for it to replace supposed macro parameters inside a string either. |
Author: | btiffin [ Sun Aug 23, 2009 10:52 pm ] | ||
Post subject: | Re: concatenating Directories | ||
In the Just in case you ever need to know department http://en.wikipedia.org/wiki/C_preprocessor#Quoting_macro_arguments The #var trick can be used with auto literal concat in C to let you build up literals in code with the preprocessor Something like
Untested, and cpp can pass on data dependent quoting weirdness And, it'll be far better to follow previous advice and not mucky muck with platform path issues unless you really really have to. Cheers |