Home > Back-end >  Can you help to look at the code, there is a mistake to understand
Can you help to look at the code, there is a mistake to understand

Time:11-09

# include
# include
# include

Typedef struct
{
Char * ch;
int length;
} HString;

Int initstring HString * (T)
{
(* T). The length=0;
(* T). Ch=NULL;
}
Int StrAssign (HString & amp; T, char * chars)
{
Int len, I;
Char * c.
If h (tc)
H free (tc);
Len=strlen (chars);
For (I=0, c=chars; * c; + + I + + c)
if(! I)
{
Tc h=NULL;
T.l ength=0;
}
The else
{
if(! (tc h=(char *) malloc (I * sizeof (char))))
exit(0);
for(i=0; iTc h=chars [I] [I];
T.l ength=I;
}
return 1;
}

Int strinsert (HString & amp; S, int pos, HString T)
{
int i,j;
If (pos<1 | | pos> S.l ength + 1)
return 0;
If (T.l ength)
{
if(! (S.c h=(char *) realloc (S.c h, (S.l ength + T.l ength) * sizeof (char))))
exit(0);
For (I=S.l ength - 1; I> Pos - 1; - I)
S.c h [I + T.l ength]=S.c h [I];
For (I=pos - 1, j=0; i<=pos + T.l ength - 2; I++ j++)
[I]=tc S.c h h [j];
S.l ength +=T.l ength;
}
return 1;
}
Int the SubString (HString & amp; Sub, HString & amp; S, int pos, int len)
{int I, j;
If (pos<1 | | pos> S.l ength | | len<0 | | len> S.l ength - pos + 1)
return 0;
If (Sub. Ch)
Free (Sub. Ch);
if(! Len)
{
Sub. Ch=NULL;
Sub. Length=0;
}
The else
{
Sub. Ch=(char *) malloc (len * sizeof (char));
For (I=pos - 1, j=0; i<=pos + len - 2; I++ j++)
Sub. Ch [j]=S.c h [I];
S.l ength=len;
}

Int strdelete (HString & amp; S, int pos, int len)
{
int i;
For (I=pos + len; i<=S.l ength; I++)
{
S.c h] [I - len - 1=S.c h [I - 1);
}
S.l ength -=len;
return 0;
}



Int Strlength (HString & amp; S)
{
Return S.l ength;
}


Int concat (HString & amp; T, HString HString S1, S2)
{
int i,j;
If h (tc)
H free (tc);
if(! (tc h=(char *) malloc ((S1) length + S2) length) * sizeof (char))))
exit(0);
for(i=0; iTc h [I]=S1. Ch [I];
T.l ength=S1. Length + S2. Length;
For (I=0, j=S1 length; jTc h [j]=S2. Ch [I];
return 1;
}
Int strcompare (HString HString S, T)
{
int i;
for(i=0; iIf (S.c h [I]! H=tc [I])
Return S.c h [I] - tc h [I];
Return S.l ength - T.l ength;
}


Int index (HString HString S, T, int pos)
{
HString sub.
Int I, n, m;
If (pos> 0)
{
N=Strlength (S);
M=Strlength (T);
I=pos.
While (i<=n - m + 1)
{
The SubString (sub, S, I, m);
If (strcompare (sub, T)!=0)
++i;
The else return I;
}
}
return 0;
}

Int main ()
{
int i;
HString S, W, P, D;
HString Sub.
HString M []={" cde "};
Char T []={" abcdefg "};

Char [] k={" 123 "};
Char [] h={" 456 "};
Initstring (& amp; S);
StrAssign (S, T);

The SubString (Sub, S, 2, 3);
for(i=0; i<3; I++)
Printf (" % c ", Sub. Ch [I]);
The index (S, M, 1);

Strdelete (S, 5, 2);

Initstring (& amp; W);
Initstring (& amp; P);
StrAssign (W, k);
StrAssign (P, h);
Strcompare (W, P);
Concat (D, W, P);
return 0;
}

CodePudding user response:

This is to do what error message are you and what is your process?

What are you going to do before you make the questions how to do and then error flagged & amp; The address-of operator is in the function parameter is the address of the type function name function parameter type the address

CodePudding user response:


Want to do is list of basic operation and implementation

CodePudding user response:

All function definitions are not legal
  • Related