Re: macro to print filename

Zhongye Jia <[email protected]> Thu, 2 Jun 2011 02:08:50 +0800
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
no need for an array, just a pointer is enough.

#include <stdio.h>

int main()
{
        char filename[] = __FILE__, *basename;
        basename = filename + sizeof(filename) - 2;
        while( basename+1 != filename && *basename != '/' ) {
                basename--;
        }
        basename++;
        printf("%s\n%s\n", filename, basename);
        return 0;
}

On Thu, Jun 2, 2011 at 00:07, ratheesh kannoth <[email protected]> wrote:
> __FILE__ macro prints relative path name of the file. I need only
> filename. How to extract this ?
>
> I dont want to use any string library - since it includes more
> Processing and needs to store the character array in executable. IS
> there any method at preprocessing level to do this .
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to [email protected]
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html