The function prototypes are as follows:
int substr (char dst[], char src[], int start, int len) {}
The goals are:
Starting from the start position of the SRC array, the position of the start character is shifted backwards,
Copies up to Len non-nul characters to a DST array. After replication is complete, the DST array must be
Ends with a nul byte. The return value of the function is the length of the string stored in the DST array.
#include <stdio.h>
int main ()
{
Char dst[10];
Char src[] = "Hello-wellcome";
substr (DST, SRC, 6, 8);
printf ("%d\n", sizeof (DST));
printf ("%d\n", strlen (DST) +1);
printf ("%s\n", DST);
System ("pause");
return 0;
}
int substr (char dst[], char src[], int start, int len)
{
char* sc = src + start;
ASSERT (DST! = null&&src! = NULL);
int n, i=0;
n = strlen (SC);
if (n < len)//Copy Len
{
Len = n;
}
while (LEN)
{
Dst[i] = Sc[i];
len--;
i++;
}
Dst[i] = ";
}
Write a function that extracts a substring from a string.