title: CS50: Segmentation Fault in Duration part of pset3, Music (C)
body: <h2>I included the proper libraries and all, this part of the code gives segmentation fault for some reason:</h2>
  
  <pre><code>int numerator = atoi(&amp;fraction[0]);  
  int denominator = atoi(&amp;fraction[2]);  
  return ((numerator / denominator) * 8);
  </code></pre>
  
  <hr>
  
  <h2>Whereas if I choose not to convert to int using atoi(), and instead do a bunch of if statements like this:</h2>
  
  <pre><code>if (fraction[0] == '1' &amp;&amp; fraction[2] == '8')
  {
      return 1;
  }
  
  else if (fraction[0] == '1' &amp;&amp; fraction[2] == '4')
  {
      return 2;
  }
  .
  .
  .
  .
  </code></pre>
  
  <hr>
  
  <p>It works.<br>
  I'm pretty confused, and I would like to use the first method because it is much more efficient.</p>
  
  <p>Edit : This is part of a problem given by Harvard in its course, CS50. The full program uses several files that Harvard wrote and that depend on each other. My role was just to write the snippet I'm asking about here. Of course I read and understood the code in the files they provided. I'm afraid I can't copy the entire program here in a way that'd make it verifiable without it being very long. I was hoping someone familiar with the course's problems could answer, or that the error would be clear in the snippet alone. Thank you regardless, I apologize for being unclear.</p>