使用windows下的_fullpath函数
// crt_fullpath.c
// This program demonstrates how _fullpath
// creates a full path from a partial path.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <direct.h>
void PrintFullPath( char * partialPath )
{
char full[_MAX_PATH];
if( _fullpath( full, partialPath, _MAX_PATH ) != NULL )
printf( "Full path is: %s\n", full );
else
printf( "Invalid path\n" );
}
int main( void )
{
PrintFullPath( "test" );
PrintFullPath( "\\test" );
PrintFullPath( "..\\test" );
}
参考:
https://baike.baidu.com/item/realpath/2895213?fr=aladdin
http://blog.csdn.net/earbao/article/details/51941696