title: C - exec to execute command with arguments?
body: <p>I am trying to run a simple C program that executes a command with some arguments:</p>
  
  <blockquote>
    <p><code>ls -l -a -i</code></p>
  </blockquote>
  
  <p>I have searched for info about the <code>exec</code> family, but don't understand all the different <code>exec</code> calls and which one to use.</p>
  
  <p>My program is:</p>
  
  <pre><code>int main(int argc, char **argv)
  {
      const char *cmd = "ls";
      const char *args[3];
      args[0] = "-l";
      args[1] = "-a";
      args[2] = "-i";
  
      execv(cmd, args); /* this line does not work */
  
      return 0;
  }
  </code></pre>
  
  <p>I thought <code>execv</code> is called with:</p>
  
  <ul>
  <li><code>char *cmd</code> as the command</li>
  <li><code>char *args[]</code> as the arguments</li>
  </ul>
  
  <p>But I'm getting errors with all different combinations and attempts.</p>