C language tempered 25

Source: Internet
Author: User

/*Topic 61: Write a function called removestring, which is used to remove a certain amount of characters from a string. The function accepts three parameters: the 1th parameter represents the source string, the 2nd parameter represents the starting position where the character needs to be deleted (position starts at 0) and the 3rd parameter represents the number of characters that need to be deleted. Eg: string "ABCD12345EFG" removestring (Text, 4, 5); The string wrong and subsequent spaces in the character array are deleted. The legacy content is the string ABCDEFG ". */#include<stdio.h>#include<stdlib.h>#include<string.h>intRemovestring (Char*pstr/*inch*/,intBeginintNumChar**pout/* out*/){    intErro_msg =0; if(pstr = = NULL | | pout==NULL) {erro_msg=1; printf ("pstr = = NULL | | Pout==null an incoming parameter cannot be an empty Erro msg:%d\n", erro_msg); returnerro_msg; }    //defining temporary variable accept parameters    Char*pin =pstr; //Allocate return memory    Char*res = (Char*)malloc(sizeof(Char)* -); intindex =0, numx=0;  while(*pin! =' /'){        if(Index >= Begin&&index < (begin+num)) {Pin++; Index++; Continue; } RES[NUMX]= *pin; //The pointer moves back onepin++; Index++; Numx++; } RES[NUMX]=' /'; *pout =Res; returnerro_msg;}intFreestring (Char**pin/*inch*/){    intErro_msg =0; if(pin==NULL) {erro_msg=1; printf ("pin==null incoming parameters cannot be empty Erro msg:%d\n", erro_msg); returnerro_msg; }    if(*pin!=NULL) {         Free(*pin); *pin =NULL; }    returnerro_msg;}voidMain () {Charstr[ -]="ABCD12345EFG"; intRET =0; //Receive return string    Char*STR2 =NULL; RET= Removestring (str,0,5, &str2); if(ret!=0) {printf ("deletion of the specified character failed! "); }    //print the characters after processingprintf (str2); printf ("\ n"); //Freeing MemoryFreestring (&str2); System ("Pause");}

C language tempered 25

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.