What is wrong with this code?

  c++, question

This code compilation can pass, but the running result prints out 0, why?

//Dynamic heap allocation storage for strings
 //by zoe
 
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <iostream>
 
 #define MAXSIZE 100
 using namespace std;
 
 typedef struct {
 char *ch;
 int length;
 int size;
 }HString;
 
 void InitString(HString &S){
 S.ch=new char[MAXSIZE];
 if(S.ch==NULL) {cerr<<"error!  \n";  exit(1);  }
 S.ch[0]='\0';
 S.length=0;
 S.size=MAXSIZE;
 }
 
 int StrLength(HString S){
 return S.length;
 }
 
 //String Copy
 void StrAssign(HString &S,HString T){
 if(S.ch) free(S.ch);
 if(!  T.ch) {exit(1);  }
 else{
 if(!  (S.ch=(char*)malloc(StrLength(T)*sizeof(char)))) {exit(1);  }
 for(int i=1;  i<=StrLength(T);  i++){
 S.ch[i]=T.ch[i];
 }
 S.length=T.length;
 S.size=T.size;
 }
 }
 
 //if s>t, the return value is greater than zero;  S=t, return value equals 0;  S<t, return less than zero
 int StrCompare(HString S,HString T){
 for(int i=0;  i<S.length&&i<T.length;  i++){
 if(S.ch[i]!  =T.ch[i]) return S.ch[i]-T.ch[i];
 }
 return S.length-T.length;
 }
 
 //Connect s2 after s1
 void Concat(HString &S1,HString &S2){
 int i=0,j;
 if((S1.length+S2.length)>MAXSIZE){
 char *dest=new char[S1.length+S2.length+1];
 if(dest==NULL) {cerr<<"error!  \n";  exit(1);  }
 char *temp=dest;
 for(int i=0;  i<S1.length;  i++) dest[i]=S1.ch[i];
 delete [] S1.ch;
 S1.ch=temp;
 S1.size=S1.length+S2.length;
 }
 for(int j=0;  j<S2.length;  j++,i++) S1.ch[i]=S2.ch[j];
 S1.ch[i]='\0';
 S1.length=S1.length+S2.length;
 }
 
 HString SubString(HString S,int pos,int len ){
 HString sub;
 sub.ch=(char*)malloc(len*sizeof(char));
 if(!  sub.ch) {cerr<<"error!  \n";  exit(1);  }
 if(pos>=S.length||pos<0||len<0||len>S.length){
 sub.ch[0]='\0';  sub.length=0;
 }
 else{
 if(pos+len-1>S.length) len=S.length-pos;
 for(int i=0,j=pos;  i<len;  i++,j++) sub.ch[i]=S.ch[j];
 sub.ch[len]='\0';
 sub.length=len;
 }
 
 return sub;
 }
 
 //Delete all substrings identical to string T in string S and return the number of deletions
 int Delet_SubString(HString &S,HString T){
 HString sub;
 HString lsub;
 InitString(sub);
 int m=StrLength(S);
 int n=StrLength(T);
 int i=1,count=0;
 while(i<=m){
 StrAssign(sub,SubString(S,i,n));
 If(StrCompare(sub,T)==0){// match equal
 InitString(sub);
 InitString(lsub);
 Concat(sub,lsub=SubString(S,1,i-1));
 Concat(sub,lsub=SubString(S,i+n,m-i-n+1));
 StrAssign(S,sub);
 n=StrLength(S);  //Note that the value of S changes after one operation
 count++;
 }
 else {
 i++;
 }
 }
 return count;
 }
 
 void PrintString(HString S){
 for(int i=0;  i<S.length;  i++){
 printf("%c ",S.ch[i]);
 }
 }
 
 int main(){
 HString S,T;
 InitString(S);
 InitString(T);
 char s1[]={"abcdefgabcimcseeokabcsf"};
 char s2[]={"bc"};
 for(int i=1;  i<=S.size;  i++){S.ch[i]=s1[i];  }
 for(int i=1;  i<=T.size;  i++){T.ch[i]=s2[i];  }
 int n=Delet_SubString(S,T);
 PrintString(S);
 printf("%d\n",n);
 return 0;
 }

There are many problems. ….

for(int i=1;  i<=S.size;  i++){S.ch[i]=s1[i];  }

This code does not copy the string. The subscript of the array starts from 0, not only the first character is skipped, but also the last character is crossed.
Moreover, I forgot to maintain its length here, causing Delet_SubString to assume its length is 0.
New resources must be delete, not free.