title: retrieve letter from string in C
body: <p>With the following C-function, I want to retrieve the letter at index idx from some string:</p>
  
  <pre><code>char get_letter(char *str, int idx)
  {
      return *(str + idx);
  }
  </code></pre>
  
  <p>For example, the following:</p>
  
  <pre><code>char s[] = "Barack";
  get_letter(s,2); 
  </code></pre>
  
  <p>should return the letter 'r'.</p>
  
  <p>Here is the whole program (name of the executable file is "retrieve"):</p>
  
  <pre><code>int printf(const char * restrict, ...);
  char get_letter(char *, int);
  
  int main(int carg, const char **varg){
    if (carg != 2) return -1;  
    printf("%s", get_letter(varg[1],1));
    return 0;           
  }
  
  char get_letter(char *str, int idx)
  {
  return *(str + idx);
  }
  </code></pre>
  
  <p>when I run the program (e.g.: ./retrieve test), instead of getting the letter "e", I get an error message ("Segmentation fault: 11").
  What is going wrong here?</p>