c retrieve file's full name or absolute path via realpath method
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> void realpath9(); int main() { realpath9(); } void realpath9() { char *file=__FILE__; char *fullName=(char *)malloc(PATH_MAX); char *res=realpath(file,fullName); if(res) { printf("Name=%s,FullName=%s,res=%s\n",file,fullName,res); } else { printf("Failed:%s\n",res); } }
The snapshot as below.