String processing of the ACM Classic algorithm: string interception

Source: Internet
Author: User
Tags first string

Syntax: Mid (char str[],int start,int Len,char strback[])

Parameters:
Str[]: Target string for operation
Start: Starts with the beginning of the first string and intercepts the Len-length characters
Len: Starts with the beginning of the first string and intercepts the Len-length characters
Strback[]: truncated to the character

return value:

0: Out of string length, intercept failed; 1: Intercept Successful

#include <stdio.h> #include <string.h>int mid (char str[],int start,int Len,char strback[]); int main () {// Char a[]= "I have a Dream";//Initialize the character array without specifying its size char Str[100];char newstr[100];//just purely stating that a character array variable would have to specify a size gets (str); In the VS2008 there will be a warning (gets unsafe. ), change gets to gets_s will not appear warning prompt int m=mid (STR,2,4,NEWSTR), if (m) {printf ("%s\n", newstr),//output string, with the same effect//puts (NEWSTR);} Else{printf ("Out of string length \ n"), or/n will wrap puts ("Out of string Length"),//output will wrap}return 0 after playing string;} int mid (char str[],int start,int Len,char strback[]) {int L,i,k=0;l=strlen (str), if (start+len>l) return 0;for (I=start ; i<start+len;i++) {strback[k]=str[i];k++;} strback[k]= ' + ';//key step return 1;}


String processing of the ACM Classic algorithm: string interception

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.