Answer to Question #52468 in C for sara

Question #52468
Write a function called removeString to remove a specified number of characters from a character string. The function should take three arguments: the source string, the starting index number in the source string, and the number of characters to remove. So, if the character array text contains the string "the wrong son", the call
removeString(text,4,6);
has the effect of removing the characters “wrong“ (the word “wrong” plus the space that follows) from the array text. The resulting string inside text is then "the son".
1
Expert's answer
2015-05-07T03:16:36-0400
Answer:
#include <stdio.h>

void removeString(char *text,int start,int number)
{
int i;
for(i=start;text[number+i]!='\0';i++)
text[i]=text[i+number];
text[i]='\0';
}

int main(){
char text[100];
printf("Input string:");
scanf("%s",text);
removeString(text,3,2);
printf("Result:%s",text);
return 0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS