[程式碼例項][Linux系統程式設計]判斷相對路徑或絕對路徑
阿新 • • 發佈:2018-12-31
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define IS_APATH(p) (*(p) == '/')
#define IS_RPATH(p) (!(IS_APATH(p)))
int main(int argc, char * argv[])
{
if((argc == 2 && strcmp(argv[1], "--help") == 0)
|| argc != 2)
{
printf("Usage: %s <path>\n" , argv[0]);
return EXIT_SUCCESS;
}
if(IS_RPATH(argv[1]))
printf("\"%s\" is relative path\n", argv[1]);
else
printf("\"%s\" is absolute path\n", argv[1]);
return EXIT_SUCCESS;
}