I have written a substring function that takes a value char array, initial value, and length and then return a substring
char* substring(char t[],int i,int l){
int k=0;
char* subs=new char[l];
while(t[k]!=0){
if(k==i){
int a=i;
int j=0;
// for (int j=0;j<l;j++)
while(j<l)
{
subs[j]=t[a];
a++;
j++;
}
if(subs!=0){
break;
}
}
k++;
}
return subs;
}
// CHECKING
int main(){
char t[20]="this is a string";
cout<<substring(t,0,4);
}
//OUTPUT
this└
everything is working properly getting exact output which I want but at the end of the output value it also return a unexpected value such as symbols and random alphabets don't know how to get rid of it **NOTE I don't want to use strings or anything else just want to clear the problem which in this programme