#include <stdio.h>
#include <string.h>

static void find_destructive(char *s) {
    char *p_sl = strrchr(s, '/');
    if (p_sl) {
        *p_sl = '\0';
        printf("[%s] [%s]\n", s, p_sl + 1);
    } else {
        printf("Cannot find any slashes.\n");
    }
}

static void find_transparent(const char *s) {
    const char *p_sl = strrchr(s, '/');
    if (p_sl) {
    	char *first = (char *)malloc(p_sl - s + 1);
    	if ( ! first) {
    	    perror("malloc for a temp buffer: ");
    	    return;
    	}
    	memcpy(first, s, p_sl - s);
    	first[p_sl - s] = '\0';
        printf("[%s] [%s]\n", first, p_sl + 1);
        free(first);
    } else {
        printf("Cannot find any slashes.\n");
    }
}

int main() {
    char s[] = "home/usr/wow/muchprogram";

    find_transparent(s);
    find_destructive(s);

    return 0;
}