title: Making a directory with a c program
body: <p>I am trying to make a C program which takes a string and makes a directory with the given name. I have made two versions thus far and they are included below but neither work like I want them to.
  But this program has 2 problems:
  1. It doesn't take input until after you click enter
  2. It makes the directory end with a question mark.</p>
  
  <pre><code>//Make Directory program
  
  #include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  
  
  void main()
  {
    char dirname[20];
    fgets(dirname, 20, stdin);
    int check;
    check = mkdir(dirname);
    printf("This is the chosen directory name: ");
    printf(dirname);
  
    if (!check)
    printf("Directory created\n");
  
   else
   {
     printf("Unable to create directory\n");
     //exit(1);
   }
  
    return;
  
  }
  </code></pre>
  
  <p>I also tried this version.
  But it segfaults whenever I try to run it.
  I have tried the inputs.
  "directory"
  and
  directory</p>
  
  <pre><code>//Make Directory program
  
  #include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  void main( char dirname[20])
  {
    int check;
    checker = mkdir(dirname);
  
    if (!checker)
    printf("Directory created\n");
  
   else
   {
     printf("Unable to make directory\n");
   }
    return;
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated</p>
  
  <hr>
  
  <p>Edit:
  Here is the new code edited given the suggestions below</p>
  
  <p>When I enter:
  $  makedir directory</p>
  
  <p>it makes  a directory named:
  p?????</p>
  
  <p>Thank you very much for your help so far.</p>
  
  <pre><code>//Make Directory program
  
  #include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  
  
  void main(int argc, char *argv[])
  {
   // char dirname[20];
  //  fgets(dirname, 20, stdin);
    int check;
    check = mkdir(argv, '.');
    //mkdir(argv, '.');
  
    if (!check)
    printf("Directory created\n");
  
   else
   {
     printf("Unable to create directory\n");
     //exit(1);
   }
  
    return;
  
  }
  </code></pre>