A program that deletes substrings without using the related string library function of C:
#include <stdio.h>
int Del_substr (char *str,char const *SUBSTR);
int My_strlen (char const *STR);
int main (void)
{
Char str[] = "ABCDEFGH";
Char *substr1 = "EFG";
Char *substr2 = "FGR";
printf ("%d\t%s\n", Del_substr (STR,SUBSTR1), str);
printf ("%d\t%s\n", Del_substr (STR,SUBSTR2), str);
return 0;
}
/**
* * STR--string
* * substr--substring
**www.bianceng.cn Finishing
* * If the substring is successfully found and deleted, the prompt returns 1, if not found then return 0
**/
int Del_substr (char *str,char const *SUBSTR)
{
int i = 0;
char *temp_str = str;
char const *TEMP_SUBSTR = substr;
int sub_len = My_strlen (substr);
while (1)
{
if (*temp_str = = *temp_substr)
{
temp_substr++;
if (*temp_substr = = ' ")
{
Break
}
}
Else
{
Temp_substr = substr;
}
if (*temp_str = = ' ")
{
return 0;
}
temp_str++;
}
Char *predel = temp_str-(sub_len-1);
while (* (Predel + (I+sub_len))!= ' ")
{
* (Predel + i) = * (Predel + (I+sub_len));
i++;
}
* (Predel + i) = ' I ';
return 1;
}
int My_strlen (char const *STR)
{
int len = 0;
while (*str++!= ' ")
{
len++;
}
return Len;
}