Logo

Programming-Idioms

History of Idiom 38 > diff from v5 to v6

Edit summary for version 6 by :

Version 5

2015-08-20, 09:57:46

Version 6

2015-08-20, 10:00:37

Idiom #38 Extract a substring

Find substring t consisting in characters i (included) to j (excluded) of string s.
(character indexes start at 0 unless specified otherwise)

Idiom #38 Extract a substring

Find substring t consisting in characters i (included) to j (excluded) of string s.
(character indexes start at 0 unless specified otherwise)

Imports
#include <stdlib.h>
#include <string.h>
Code
char *t=malloc((j-i+1)*sizeof(char));
strncpy(t,s+i,j-i);