linux C++ gets the instance code for the absolute path to the file

  • 2020-05-10 18:32:38
  • OfStack

When providing the ftp service, you need to get the absolute path of the file. Record 1 here.


#include <stdlib.h>
#include <stdio.h>
#include <limits.h>

int main(){
 const char *file_name = "filename";
 char abs_path_buff[PATH_MAX];

 // Get file path ,  To fill abs_path_buff
 //realpath The function returns : null Indicates failed fetch ;  Otherwise return to point abs_path_buff A pointer to the 
 if(realpath(file_name, abs_path_buff)){
  printf("%s %s\n", file_name, abs_path_buff);
 }
 else{
  printf("the file '%s' is not exist\n", file_name); 
 }

 return 0;
}

Related articles: