自分自身のファイル名を知る方法
Posted feedbacks - C
1 2 3 4 5 6 7 | #include <libgen.h>
#include <stdio.h>
int main( int argc, char *argv[] ){
printf("%s\n", basename(argv[0]) );
return 0;
}
|
Windows版です
1 2 3 4 5 6 7 8 9 | #include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv[] ) {
char command[BUFSIZ];
sprintf(command, "dir /B \"%s\"", argv[0]);
system(command);
return 0;
}
|
今のところWindowsにのみ対応しています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <stdio.h>
/* The backslash is 0x5C in ASCII. */
#ifdef WIN32
#define PASS_SLICE 0x5C
#define HAVE_SLICE TRUE
#endif
#ifdef HAVE_SLICE
#include <string.h>
#endif
int main(int argc, char* argv[])
{
char *point;
#ifdef HAVE_SLICE
point = strrchr(argv[0], PASS_SLICE);
#else
point = NULL;
#endif
printf("%s\n", (point == NULL) ? argv[0] : ++point);
return 0;
}
|


ところてん
#5728()
Rating1/1=1.00
see: #3301
[ reply ]