标签:从字符串中提取子字符串
#include <assert.h> int substr(char dst[], char src[], int start, int len) { int srcLen = strlen(src); int left = 0; assert(dst); assert(src); if (srcLen < start) { return -1; } while (start--) { src++; //指针向后偏移start } left = srcLen - start; if (left < len) { len = left; } int ret = len; while (len--) { *dst++ = *src++; } *dst = ‘\0‘; return ret; } int main() { char dest[10]; char *p = "bit-tech"; substr(dest, p, 4, 4); printf("%s\n", dest); return 0; }
标签:从字符串中提取子字符串
原文地址:http://10706198.blog.51cto.com/10696198/1758623