Extracts a substring from a string

Source: Internet
Author: User

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

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.