title: Run a C program from within a C program
body: <p>The question pretty much explains itself I have three different C programs and to try and compare their efficiency I tried to test their runtime by making them run several times varying their parameter (which is proportional to time taken) and write how long it takes each program to run for certain parameter (so later i can plot the results).</p>
  
  <p>The following is my code</p>
  
  <pre><code>   # include &lt;stdio.h&gt; 
      # include &lt;stdlib.h&gt;
      # include &lt;math.h&gt;
      # include &lt;time.h&gt;  
  
     int main(void){
  
      int i;
      struct timeval bni, bmi, bfi, bnf, bmf, bff;
      FILE *in;
      char filename1[30] = "shuff.dat";
      int a1,a2,b1,b2,c1,c2;
      char command[100];
  
      in = fopen(filename1, "w");
      //for(i = 0; i&lt;=100000; i +=100){
      for(i = 0; i&lt;=10; i +=1){
  
          if (snprintf(command, sizeof(command), "./barajas_n.x %d", i) &lt; sizeof(command)){
          a1 = gettimeofday(&amp;bni , NULL);
          system(command);
          a2 = gettimeofday(&amp;bnf , NULL);
          }
  
          if (snprintf(command, sizeof(command), "./barajas_m.x %d", i) &lt; sizeof(command)){
          b1 = gettimeofday(&amp;bmi , NULL);
          system(command);
          b2 = gettimeofday(&amp;bmf , NULL);
          }
  
          if (snprintf(command, sizeof(command), "./barajas_fy.x %d", i) &lt; sizeof(command)){
          c1 = gettimeofday(&amp;bfi , NULL);
          system(command);
          c2 = gettimeofday(&amp;bff , NULL);
          }
          fprintf(in, "%d %d %d %d \n", i, (a2-a1),(b2-b1),(c2-c1));
      }
      fclose(in);
  }
  </code></pre>
  
  <p>I get the following message on the terminal window: </p>
  
  <p><img src="https://i.stack.imgur.com/ybLgT.png" alt="Error message"></p>
  
  <p>Which means this program is running all of its steps, only not correctly executing the programs I want to time.</p>
  
  <p>I've tested all three programs individually in the terminal like this</p>
  
  <pre><code>./barajas_*.x i
  </code></pre>
  
  <ol>
  <li>Can someone please tell me why system() is taking it's input as a directory and,</li>
  <li>how to tell system() it to stop taking it as a directory and execute it?</li>
  </ol>
  
  <p>EDIT: After a long discusion in a chat room the problem was as said by Jonathan Leffler: " a mismatch between the actual command name that existed and the command name that the program was attempting to run." </p>
  
  <p>The actual question is answered by iharob's contribution, for anyone interested the snippet he provided should work if the command name matches the command name being run by the program.</p>