如何检查数组中的每个字符串是否以/结尾

时间:2019-02-13 05:25:12

标签: c shell

我试图找出数组中哪些字符串以/结尾 但我不确定如何检查

for(int k = 0; k < num_paths; k++) {
    path = malloc(strlen(paths[k]) + strlen(line) + 2);
    if(path == NULL) {
       exit(1);
    }
    if (paths[k] != '/') { // here is where I am trying to check
       strcpy(path, paths[k]);
       strcat(path, "/");
       strcat(path, commands[0]);
       if(access(path, X_OK) == 0) {
          execv(path, commands);
          error();
       }
    } else {
       strcpy(path, paths[k]);
       strcat(path, commands[0]);
       if(access(path, X_OK) == 0) {
          execv(path, commands);
          error();
       }
    }
    free(path);
}

我希望找到每个没有/

的字符串

0 个答案:

没有答案