I would like to display my current C file using C program. I know that the executable name can be obtained by argv[0]. But I want the file name as 'hello.c' for example. Is it possible?
I would like to display my current C file using C program. I know
Share
A single program can be comprised of several C files. So which one are you looking for?
The
__FILE__macro was made for this reason. It is replaced by the preprocessor with the name of the current source (.C) file being compiled.main.c
one.c
Output (assuming executable name is “hello.exe”):
See also:
__FILE__,__LINE__, and__FUNCTION__usage in C++