#include <stdio.h>
#include <string.h>
#include <assert.h>
char* get_part_path(const char* s, const char* find_path) {
// todo
return NULL;
}
int main() {
assert(strcmp(get_part_path("/base/4", "/"), "base") == 0);
assert(strcmp(get_part_path("base/4", "/"), "base") == 0);
assert(strcmp(get_part_path("/base/4", "/base"), "4") == 0);
assert(strcmp(get_part_path("base/4", "/base"), "4") == 0);
assert(strcmp(get_part_path("base/4", "/base/4"), "4") == 0);
printf("All tests passed!\n");
return 0;
}
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
char* get_part_path(const char* s, const char* find_path) {
const char* start = strstr(s, find_path);
if (!start) {
return NULL;
}
start += strlen(find_path);
while (*start == '/') {
start++;
}
const char* end = strchr(start, '/');
if (!end) {
end = s + strlen(s);
}
size_t len = end - start;
char* result = (char*)malloc(len + 1);
if (result) {
strncpy(result, start, len);
result[len] = '\0';
}
return result;
}
int main() {
assert(strcmp(get_part_path("/base/4", "/"), "base") == 0);
assert(strcmp(get_part_path("base/4", "/"), "base") == 0);
assert(strcmp(get_part_path("/base/4", "/base"), "4") == 0);
assert(strcmp(get_part_path("base/4", "/base"), "4") == 0);
assert(strcmp(get_part_path("base/4", "/base/4"), "4") == 0);
printf("All tests passed!\n");
return 0;
}