title: Why am I getting segmentation fault for this program?
body: <p>I have to write a program which reads dates and todo-s as command line arguments and puts these in a text-file (line by line).</p>
  <p><strong>Correct input:</strong></p>
  <pre><code>./todo 13:58 todo1 00:00 todo2 08:30 todo3
  </code></pre>
  <p><strong>Wrong input:</strong></p>
  <pre><code>./todo 13:58 todo1 24:00 todo2 08:30 todo3 or ./todo 13:58 todo1 todo2 00:00 08:30 todo3
  </code></pre>
  <p>Correct <strong>todolist.txt</strong> file:</p>
  <pre><code>13:58 - todo1
  00:00 - todo2
  08:30 - todo3
  </code></pre>
  <p>The code is compiled successfully, but when I run the program, I get segmentation fault:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;stdlib.h&gt;
  
  bool isValidTime(char* argv)
  {
      char hour[2] = {0};
      char minute[2] = {0};
  
      for (unsigned int i = 0; argv[i] != ':'; i++) {
          hour[i] = argv[i];
      }
      int hourNum = atoi(hour);
      if (!(hourNum &gt;= 0 &amp;&amp; hourNum &lt; 24)) {
          return false;
      }
  
      for (unsigned int i = 3; i &lt; sizeof(*argv) / sizeof(argv[0]); i++) {
          minute[i] = argv[i];
      }
      int minuteNum = atoi(minute);
      if (!(minuteNum &gt;= 0 &amp;&amp; minuteNum &lt; 60)) {
          return false;
      }
  
      return true;
  }
  
  bool isValidTodo(char* argv)
  {
      for (unsigned int i = 0; i &lt; sizeof(*argv) / sizeof(argv[0]); i++) {
          if (!(argv[i] &gt;= 'a' &amp;&amp; argv[i] &lt;= 'z')) {
              return false;
          }
      }
      return true;
  }
  
  int main(int argc, char* argv[])
  {
      if (argc &lt; 3) {
          printf(&quot;Incorrect input!\n&quot;);
          return 1;
      }
      
      FILE* file;
      file = fopen(&quot;todolist.txt&quot;, &quot;w&quot;);
      if (file == NULL) {
          printf(&quot;File failed to open.\n&quot;);
          return 1;
      }
  
      for (int i = 1; i &lt; argc; i++) {
          if (!(isValidTime(argv[2 * i - 1]) &amp;&amp; isValidTodo(argv[2 * i]))) {
              printf(&quot;Incorrect input!\n&quot;);
          }
          fprintf(file, &quot;%s - %s\n&quot;, argv[2 * i - 1], argv[2 * i]);
      }
  
      fclose(file);
  
      return 0;
  }
  </code></pre>