Write a function that extracts a substring from a string.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.