title: how to shift elements of array (or c-string) left by a given number indexes
body: <p>I am writing a function to shift the characters of my c-string left by a given number of characters. Currently the function will shift the characters left but I am losing one. I know it is some sort of indexing issue with my for loop, but I can't pin it down.</p>
  
  <p>EDIT: By shift left I mean:</p>
  
  <p>Given a starting c-string of a, b, c, d 
  if shifted left one index this same array would equal b, c, d, a
  if shifted left two indexes this same c-string would equal c, d, a, b</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  void shiftleft (char myarray[], int size, int shiftBy)
  {
  
  char temp;
  
  for (int i=size-1; i &gt; 0; i--)
  {
      temp = myarray[size+shiftBy];
      myarray[size+shiftBy] = myarray[i];
      myarray[i] = temp;
  }
  
  
  }
  
  int main() {
      char myarray[20] = "test";
      int size = 4;
      shiftleft (myarray, size, 1);
  
      for(int i = 0; i &lt; size+1; i++){
      cout &lt;&lt; myarray[i];
      }
  
  
      return 0;
  }
  </code></pre>
  
  <p>Here is my working function that shifts each element to the right, all I need to do is reverse this loop, and move the elements left, as in this way: &lt;----</p>
  
  <pre><code>//function bloack
  void shiftright (char myarray[], int size, int shiftBy)
  {
      if(shiftBy &gt; size){
          shiftBy = shiftBy - size;
      }
      if(size == 1){
          //do nothing
      }
      else{
          char temp;
          //for loop to print the array with indexes moved up (to the right) --&gt; by 2
          for (int i=0; i &lt; size; i++)
          {
              temp = myarray[size-shiftBy];
              myarray[size-shiftBy] = myarray[i];
              myarray[i] = temp;
          }
  
      }
  }
  </code></pre>