Created
February 17, 2017 20:10
-
-
Save mishadoff/e24603c250364e09080a4f4c7d59944a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main(int argc, char *argv[]) { | |
if (argc != 2) { | |
fprintf(stderr, "[ERROR] Provide a path!\n"); | |
return 1; | |
} | |
char* path = argv[1]; | |
int slashes_to_delete = 0; | |
for (int i = strlen(path) - 1; i >= 0; i--) { | |
if (path[i] == '.') slashes_to_delete++; | |
if (slashes_to_delete > 0) { | |
if (path[i] == '/') slashes_to_delete--; | |
path[i] = '\1'; | |
} | |
} | |
printf("%s\n", path); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment