Skip to content

Instantly share code, notes, and snippets.

@mishadoff
Created February 17, 2017 20:10
Show Gist options
  • Save mishadoff/e24603c250364e09080a4f4c7d59944a to your computer and use it in GitHub Desktop.
Save mishadoff/e24603c250364e09080a4f4c7d59944a to your computer and use it in GitHub Desktop.
#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