Write a function that extracts a substring from a string. The function prototypes are as follows:
int substr (char dst[], char src[],int start, int len)
{}
The goal is to start by shifting the starting position of the SRC array backward from the start character to the maximum number of Len non-NUL characters to the DST array. After the copy 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.
#include <stdio.h> #include <stdlib.h> #define LEN 2int substr (char dst[], char src[], int start, int LEN) {int i = 0;while ((src[start-1]! = ' src[start++-1 ') && (I<len)) {dst[i++] =];} Dst[i] = ';p rintf ("str1=%s\n", DST); return i;} int main () {char Str1[len+1];char str2[] = "ABCDEFG hijklmn opqrst uvwxyz"; int LEN = 0;LEN=SUBSTR (Str1,str2,3,len);p rintf ( "Length:%d", Len); System ("pause"); return 0;}
Extracts a substring from a string