I have this function that is suppouse to return a number that should be or 1 or 2 or 4, but when the division happens, the variable duracion always get the value 0 as result. I have tried a lot of changes but no one was the solution.
// Converts a fraction formatted as X/Y to eighths
int duration(char* fraction)
{
// TODO
if (strlen(fraction) == 3)
{
// Asignacion de los caracteres de la fraccion a un array para
convertirlos en numeros despues.
int a = atoi(&fraction[0]);
int b = atoi(&fraction[2]);
// Busqueda de errores ---------------------------------------
if ((fraction[0] != '1') && (fraction[0] != '3'))
{
fprintf(stderr, "octave most be formated as X/Y, where X
can't be greater than 8\n");
return 1;
}
else if (fraction[1] != '/')
{
fprintf(stderr, "octave most be formated as X/Y\n");
return 1;
}
else if ((fraction[2] % 2 != 0) || (fraction[2] < 0))
{
fprintf(stderr, "octave most be formated as X/Y, where Y
most be a positive pair number\n");
return 1;
}
// Fin de busqueda de errores -------------------------------
float duracion = (a / b) * 8;
return duracion;
}
else
{
fprintf(stderr, "Note lenght most be formated as X/Y\n");
return 1;
}
}