Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Substring of char[] in c++

I have

  char t[200];
  cin.get(s, 200);
  int i = 5; 
  int j = 10;

Is there any simple way to get substriing(i,j) from t beside copying every element seperately to the another array? No strings etc. just char t[200].

like image 736
Yoda Avatar asked Mar 23 '13 12:03

Yoda


1 Answers

char* substr(char* arr, int begin, int len)
{
    char* res = new char[len + 1];
    for (int i = 0; i < len; i++)
        res[i] = *(arr + begin + i);
    res[len] = 0;
    return res;
}
like image 115
Akenolt Avatar answered Oct 05 '22 23:10

Akenolt