/* Answer on Question#52420 - Subject - Programming, C++ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int removeString(char* ch, int s, int n )
{
char *buf = new char[256]; /* memory for result string*/
char *buf_p = buf; /* pointer to beginning of buf*/
memset(buf,0,256); /* to zero memory*/
char *ch_p = ch; /*pointer to beginning of ch*/
int length = 0;
while ( *ch_p != '\0' ) /* defines length of string*/
{
length++;
ch_p++;
}
/* copying needed chars from ch to result string*/
for (int i=0; i<=s-1; i++)
{
*buf = *ch;
ch++;
buf++;
}
ch = ch+n*sizeof(char); /* increment ch by n */
for (int i=n; i<=length; i++)
{
*buf = *ch;
ch++;
buf++;
}
printf("%s\n",buf_p); /*print result*/
return 0;
}
int main() /* main function*/
{
char ch[] = "the wrong son"; /*string for test*/
removeString(ch,4,6); /* func.call*/
system("pause");
return 0;
}
Comments
Leave a comment