/*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