How to get the current executable name in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

#ifdef _WIN32
#define PATH_SEP '\\'
#else
#define PATH_SEP '/'
#endif

int main(int argc, char* argv[])
{
    char* s = strchr(argv[0], PATH_SEP);

    s = s ? s + 1 : argv[0];

    puts(s);

    return 0;
}



/*
run

TheForm\3d\x64\Debug\3d.exe

*/

 



answered Jun 2, 2025 by avibootz

Related questions

1 answer 243 views
2 answers 234 views
1 answer 263 views
1 answer 242 views
1 answer 270 views
1 answer 270 views
2 answers 297 views
...