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.

 

 

posted @ 2021-11-21 23:51  FredGrit  阅读(33)  评论(0编辑  收藏  举报