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

Time:11-20

#include
#include
#include
# define MAXLEN 100
Typedef struct
{
Char ch [MAXLEN];
int len;
} sstring;
//create a string
Void StrAssign (sstring & amp; STR, char CSTR [])
{
Int I;
For (I=0; CSTR [I]!='\ 0'; I++)
STR. Ch [I]=CSTR [I];
STR. Len=I;
}
//list of insert
Int strinsert (sstring * s, int pos, sstring t)
{
int i;
If (pos<0 | | pos> S - & gt; Len)
return 0;
If (s - & gt; Len + t.l en<=MAXLEN)
{
For (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; i{
S - & gt; Ch + pos [I]=tc h [I];
S - & gt; Len=s - & gt; Len + t.l en;
}
}
Else if (pos + t.l en<=MAXLEN)
{
For (I=MAXLEN - 1; I> T.l en + pos - 1; 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=MAXLEN;
}
The else
{
for(i=0; iS - & gt; Ch + pos [I]=tc h [I];
S - & gt; Len=MAXLEN;
}
return 1;

}
//delete
Int strdelete (sstring * s, int pos, int len)
{
int i;
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);
}
//output
Void the Output (sstring s)
{
int i;
For (I=0; i Printf (" % c ", s.c h [I]);
printf("\n");
}
Void main ()
{
Char c [100];
Sstring STR, newstr;
int i,j;
Printf (" please input to create a string: ");
The scanf (" % s ", c);
StrAssign (STR, c);
The Output (STR);
//insert
Printf (" please enter a string to insert: ");
The scanf (" % s ", c);
StrAssign (STR, c);
Printf (" please enter to insert position: ");
The scanf (" % d ", & amp; i);
Strinsert (& amp; Newstr, I, STR);
Printf (" results ");
The Output (newstr);
//delete
Printf (" please input you want to remove location: ");
The scanf (" % d ", & amp; i);
Printf (" please input you want to delete your length: ");
The scanf (" % d ", & amp; J);
Strdelete (& amp; Newstr, I, j);
Printf (" delete after: \ n ");
The Output (newstr);
}
Where is wrong

CodePudding user response:

What's error message

CodePudding user response:

No error message is right, but perform when inserted delete the result not to
  • Related