In this program, we will use __FILE__ macro to print the name of the source code file. As we know that, a project contains multiple files, so we can print the name of the source code file from any source file function in the project.
__FILE__ is a preprocessor macro in C language that is used to get the full path to the current file. It is useful for debugging to generate the log statements, error messages intended for programmers, when throwing exceptions, or when writing debugging code.
The source code to print the name of the source code file is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.
// C program to print the name of
// source code file
printf("Name of source file: %s\n", __FILE__);
Name of source file: main.c
As we know that, a project may contain multiple source code files. Then if we want to print the name of any source code file from any function. Then we can use __FILE__ macro to print the name of the source code file
total answers (1)
start bookmarking useful questions and collections and save it into your
own study-lists, login now to start creating your own collections.