write a function that extracts a substring from a string. The function prototype is as follows: Int substr (Char dst[], char src[],int start, int len) {} target: from src the starting position of the array starts at the position of the start character backward, copying up to len non-nul characters to the &NBSP;DST array. After copying is complete, the,dst array must end with nul bytes. The return value of the function is the length of the string stored in the dst array. Code implementation: #include <stdio.h> #include <assert.h>int substr (Char dst[], char src[], int start, int len) {assert (DST); assert (SRC); int ret = 0;while (start) {src++; start--;} if (strlen (src) < len) {Len = strlen (src);} ret = len;while (len) {*dst++ = *src++;len--;} *dst = ' + '; return ret;} Int main () {char *p = "Bit-tech"; char arr[10];char array[10] = {0};int ret = substr (arr, p, 4,5);p rintf ("%d\n", ret);p rintf ("%s\n", arr); System (" Pause "); return 0;}
This article is from the "vs LV" blog, so be sure to keep this source http://survive.blog.51cto.com/10728490/1706007
"C Language" extracts substrings