xxxxxxxxxx
char subbuff[5];
memcpy( subbuff, &buff[10], 4 );
subbuff[4] = '\0';
xxxxxxxxxx
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, World!";
char sub[10];
// Extract substring starting at index 7 and length 5
strncpy(sub, str + 7, 5);
sub[5] = '\0';
printf("Substring: %s", sub);
return 0;
}
xxxxxxxxxx
//where we want the word "test" and we know its position in the string
char *buff = "this is a test string";
printf("%.*s", 4, buff + 10);