Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Macro is not working properly it prints only the file name

#include <stdio.h>

#define LINE_FILE ("Line %d of file %s", __LINE__, __FILE__)


int main(void) {
    const char* str = LINE_FILE;
    printf("%s\n", str);
    printf("Line %d of file %s\n", __LINE__, __FILE__);
}

First print statement only prints the file name and not the complete line.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you want a string pre-formatted like that, here’s how you do it:

#include <stdio.h>

#define STR_IMPL(x) #x
#define STR(x) STR_IMPL(x)
#define LINE_FILE ("Line " STR(__LINE__) " of file " __FILE__)


int main() {
    printf("%s\n", LINE_FILE);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading