title: Segmentation fault with bool - CS50 plurality
body: <p>I am working on cs50 plurality problem. When I try to vote for a candidate that wasn't in my argv I expected &quot;Invalid vote.\n&quot; to be printed however my program ends in Sementation fault. Could anyone explain why? I think my logic for my bool vote may be flawed but I am not sure. Thank you!</p>
  <pre><code>#include &lt;cs50.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  // Max number of candidates
  #define MAX 9
  
  // Candidates have name and vote count
  typedef struct
  {
      string name;
      int votes;
  }
  candidate;
  
  // Array of candidates
  candidate candidates[MAX];
  
  
  
  // Number of candidates
  int candidate_count;
  
  // Function prototypes
  bool vote(string name);
  void print_winner(void);
  
  int main(int argc, string argv[])
  {
      
      // Check for invalid usage
      if (argc &lt; 2)
      {
          printf(&quot;Usage: plurality [candidate ...]\n&quot;);
          return 1;
      }
  
      // Populate array of candidates
      candidate_count = argc - 1;
      if (candidate_count &gt; MAX)
      {
          printf(&quot;Maximum number of candidates is %i\n&quot;, MAX);
          return 2;
      }
      for (int i = 0; i &lt; candidate_count; i++)
      {
          candidates[i].name = argv[i + 1];
          candidates[i].votes = 0;
      }
  
      int voter_count = get_int(&quot;Number of voters: &quot;);
  
      // Loop over all voters
      for (int i = 0; i &lt; voter_count; i++)
      {
          string name = get_string(&quot;Vote: &quot;);
  
          // Check for invalid vote
          if (!vote(name))
          {
              printf(&quot;Invalid vote.\n&quot;);
          }
      }
  
      // Display winner of election
      print_winner();
      
      
      
  }
  
  // Update vote totals given a new vote
  bool vote(string name)
  {
      for (int i = 0; i &lt; MAX; i++)
      {
          if (strcmp(candidates[i].name, name) == 0)
          {
              return true;
              
          }
      }
      return false;
      
  }
  
  // Print the winner (or winners) of the election
  void print_winner(void)
  {
      // TODO
      return;
  }
  </code></pre>
  <p>.......................................
  .......................................
  .......................................
  ...................................</p>