title: Segmentation fault while using argv[]
body: <p>I keep running into a "Segmentation Fault" while trying to enter less than 5 parameters into the program. I know Java, but am new to C, and I'm just not sure what is going on. I'm just simply trying to convert user entered kg (as a parameter) to the number of Prius' in weight it would be, to the decimal.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stddef.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  int main(int argc, char *argv[]) //Argc is the argument count, argv is the argument vector
  {
  
      //Initialize the toyota/user variables  
      int toyota = 1325; //Toyota weight in kg
      int paramOne = atoi(argv[1]);
      int paramTwo = atoi(argv[2]);
      int paramThree = atoi(argv[3]);
      int paramFour = atoi(argv[4]);
  
      //This if will check to see if there are too many parameters    
      if (argc &gt;= 5)
      {
          printf("Error: Too many parameters.\n");
          printf("Usage: ./HW1 arg1 [arg2 ... arg4].\n");
      }
  
      //This if will check to see if there are too few parameters
      if (argc &lt; 2)
      {
          printf("Error: Too few parameters.\n");
          printf("Usage: ./HW1 arg1 [arg2 ... arg4.\n");
      }
  
  
      //If there are a correct amount of parameters, this will print the TP count
      if ((argc &gt;= 1) &amp;&amp; (argc &lt;= 4))
      {
          printf("%d number of parameters.\n", argc);     
  
          if(argc &gt;= 1)
          {
  
              printf("%d kg = %d TP.\n", paramOne, paramOne/toyota); //Parameter divided by TP
          }
  
          if(argc &gt;= 2)
          {
              printf("%d kg = %d TP.\n", paramTwo, paramTwo/toyota);  
          }
  
          if(argc &gt;= 3)
          {
              printf("%d kg = %d TP.\n", paramThree, paramThree/toyota);  
          }
  
          if(argc &gt;= 4)
          {
              printf("%d kg = %d TP.\n", paramFour, paramFour/toyota);    
          }
  
  
  
  
      }
  
  }
  </code></pre>