Home > Back-end >  Insert to delete
Insert to delete

Time:11-21

# include & lt; stdio.h>
# include
# define MAXSIZE 40

//structure
Typedef struct {
Char ch [MAXSIZE];
Int len.
} sstring;
//insert
Int strinsert (sstring * s, int pos, sstring t)
{
int i;
Printf (" please enter what you want to insert position: ");
The scanf (" % d ", & amp; Pos);
If (pos<0 | | pos> S - & gt; Len)
Return (0);
If (s - & gt; Len + t.l enFor (I=s - & gt; Len + t.l en - 1; I>=t.l en + pos. I -) {
S - & gt; Ch [I]=s - & gt; Ch [I - t.l en];
}
for(i=0; iS - & gt; Ch + pos [I]=tc h [I];
}
S - & gt; Len=s - & gt; Len + t.l en;
}
Else if (pos + t.l enFor (I=MAXSIZE - 1; I> T.l en + pos - 1; I -)
{
S - & gt; Ch [I]=s - & gt; Ch [I - t.l en];
}
for(i=0; i{
S - & gt; Ch [I]=s - & gt; Ch [I - t.l en];
}
S - & gt; Len=MAXSIZE;
}
The else
{
for(i=0; iS - & gt; Ch + pos [I]=tc h [I];
S - & gt; Len=MAXSIZE;;
}
The return (1);
}
//delete
Int strdelete (sstring * s, int pos, int len)
{
int i;
Printf (" please input you want to remove location: ");
The scanf (" % d ", & amp; Pos);
Printf (" please input you want to delete your length: ");
The scanf (" % d ", & amp; Len);
If (pos<0 | | pos> (s - & gt; Len - len))
{
Printf (" delete the location of the unreasonable!" );
Return (0);
}
For (I=pos + len; iS - & gt; Ch [I - len]=s - & gt; Ch [I];
S - & gt; Len=s - & gt; Len - len;
The return (1);
}
Void main ()
{
Sstring s, t;
Int pos=0, len=0;
//the string
Printf (" please enter the string s \ n ");
The scanf (" % s ", s.c h);
printf("\n");
//substring
Printf (" please input substring t \ n ");
The scanf (" % s ", tc h);
printf("\n");
//insert
Strinsert (& amp; S, pos, t);
Printf (" % s ", s);
//delete
Strdelete (& amp; S, pos, len);
Printf (" % s ", s);
}
Where is right
  • Related