title: How can I find the the position of the k-th occurrence of a character in an array?
body: <p>I'm writing a program which takes a string, a single character and an integer number <em>k</em>, then it finds the k-th occurence of given character in given string.</p>
  
  <p>I think the code is correct but the code below doesn't give proper results.</p>
  
  <pre><code>char ch[100];
  char character;
  int n;
  cout &lt;&lt; endl &lt;&lt; "Type a string of characters : ";
  gets_s(ch);
  cout &lt;&lt; endl &lt;&lt; "Enter a single Character : ";
  cin &gt;&gt; character;
  cout &lt;&lt; "Enter the event : ";
  cin &gt;&gt; n;
  if ( func_1( ch,  character,  n)!=-1)
      cout &lt;&lt; endl &lt;&lt; n &lt;&lt; "th event is in the position number  " &lt;&lt; (ch, character, n)&lt;&lt; endl;
  else
      cout &lt;&lt; "Event couldn't be found  ." &lt;&lt; endl;
  }
  
   int func_1(char ch[], char character, int n)
   {
      int i = 0;
      int c = 0;
  
      do
      {
         i++;
      } while (ch[i] != '\0');
  
      int j;
  
      for (j = 0; j &lt; i-1;)
      {
  
          if (ch[j] == character)
              c = c + 1;
  
          j++;
      }
  
      if (c == n)
          return j-1;
  
      else
          return -1;
  }
  </code></pre>