#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *get_last_N_characters(char s[], int N) {
char *last_N_chars = malloc(strlen(s) + 1);
if (last_N_chars == NULL) {
puts("malloc error");
exit(1);
}
strncpy(last_N_chars, s + strlen(s) - N, N);
last_N_chars[N] = '\0';
return last_N_chars;
}
int main(void) {
char s[] = "java c c++ c# php python";
int N = 12;
char *p = get_last_N_characters(s, N);
printf("%s", p);
free(p);
}
/*
run:
# php python
*/