Created
May 12, 2020 11:36
-
-
Save whb07/6bcb1a42edbcd8a1f3d8fe53623fcc84 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
int findLastSlash(const char *filepath, int len_filepath){ | |
int idx = 0; | |
int location = -1; | |
while(filepath[idx] != '\0' && idx < len_filepath){ | |
if(filepath[idx] == '\\' || filepath[idx] == '/'){ | |
location = idx; | |
} | |
idx++; | |
} | |
return location; | |
} | |
char * getBaseName(char *filepath, int len_filepath) { | |
int location = findLastSlash(filepath, len_filepath); | |
char *tmp; | |
if(location > -1){ | |
location++; | |
tmp = (char *) malloc((unsigned long)(len_filepath - location)); | |
int idx = 0; | |
while(location < len_filepath && filepath[location] != '\0'){ | |
tmp[idx] = filepath[location]; | |
idx++; | |
location++; | |
} | |
tmp[idx] = '\0'; | |
return tmp; | |
} | |
tmp = (char *) malloc((unsigned long)(len_filepath)); | |
strncpy(tmp, filepath, (unsigned long) len_filepath); | |
return tmp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment