I included the proper libraries and all, this part of the code gives segmentation fault for some reason:
int numerator = atoi(&fraction[0]);
int denominator = atoi(&fraction[2]);
return ((numerator / denominator) * 8);
Whereas if I choose not to convert to int using atoi(), and instead do a bunch of if statements like this:
if (fraction[0] == '1' && fraction[2] == '8')
{
return 1;
}
else if (fraction[0] == '1' && fraction[2] == '4')
{
return 2;
}
.
.
.
.
It works.
I'm pretty confused, and I would like to use the first method because it is much more efficient.
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.