[代码实例][Linux系统编程]判断相对路径或绝对路径

来源:互联网 发布:ubuntu输入密码后卡住 编辑:程序博客网 时间:2024/06/10 01:14
#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;}
0 0
原创粉丝点击