/ Published in: C
Expand |
Embed | Plain Text
// Extract a substring from an existing string, return the length of the substring // dst: receive the substring // src: the source string to extract from // start: extract start with the 'src' + 'start' char, zero based; no bound check // len: length of the substring; may be shorter than expected. // Ansi string only! int substr(char* dst, char* src, int start, int len) { char* d = dst; char* s = src + start; while (len-- > 0) { if (*s == '\0') { *d = ''; return d - dst; } *d++ = *s++; } *d = '\0'; return d - dst; } int main() { char s[1024] = { '\0' }; }
You need to login to post a comment.
