title: C language: try to implement IndexOf function
body: <p>I try to learn <code>C Language</code> and something is not clear to me.
  I want to write <code>IndexOf</code> function that search for char inside <code>string</code> and return the <code>Index</code> number.
  I am running this under <code>ubuntu</code> and compile using this:</p>
  
  <pre><code>test1: test.c
      gcc -g -Wall -ansi -pedantic test.c -o myprog1
  </code></pre>
  
  <p>This is what i have try:</p>
  
  <pre><code>int c;
  int result;
  
      printf("Please enter string: ");
      scanf("%s", str1);
  
      printf("Please enter char: ");
      scanf("%d", &amp;c);
  
      result = indexof(str1, c);
      printf("Result value: %d\n", result);
  </code></pre>
  
  <p>And this is my function:</p>
  
  <pre><code>int indexof(char *str, int c)
  {
      int i;
      for (i = 0; i &lt; strlen(str); i++)
      {
          if (str[i] == c)
              return i;
      }
  
      return -1;
  }
  </code></pre>
  
  <p>So my problem is that my function return <code>-1</code> all the time</p>