Fucntion returns -1, Why?
This function that I have returns '-1' whenever it enters the last else can anyone tell me why so I can go about fixing it?? (Hope Indentation is correct)
Perhaps the fucntion wants to return something to main before it calls itself again and defaults to -1 ??? Or is the problem with scanf? Does it not like reading in a value for 'note' again when it already has one stored (previously in main)???
Code:
int convert(const char *note){
if( strcmp(note,"C") == 0 || strcmp( note, "c")==0 ||strcmp( note, "B#" ) == 0 || strcmp( note, "b#")==0)
return 0;
else if( strcmp( note, "C#" ) == 0 || strcmp( note, "c#")==0||strcmp( note, "Db" ) == 0 || strcmp( note, "db")==0 )
return 1;
else if( strcmp( note, "D" ) == 0 || strcmp( note, "d")==0)
return 2;
else if( strcmp( note, "D#" ) == 0 || strcmp( note, "d#")==0||strcmp( note, "Eb" ) == 0 || strcmp( note, "eb")==0 )
return 3;
else if( strcmp( note, "E" ) == 0 || strcmp( note, "e")==0||strcmp( note, "Fb" ) == 0 || strcmp( note, "fb")==0 )
return 4;
else if( strcmp( note, "F" ) == 0 || strcmp( note, "f")==0||strcmp( note, "E#" ) == 0 || strcmp( note, "e#")==0 )
return 5;
else if( strcmp( note, "F#" ) == 0 || strcmp( note, "f#")==0||strcmp( note, "Gb" ) == 0 || strcmp( note, "gb")==0 )
return 6;
else if( strcmp( note, "G" ) == 0 || strcmp( note, "g")==0 )
return 7;
else if( strcmp( note, "G#" ) == 0 || strcmp( note, "g#")==0||strcmp( note, "Ab" ) == 0 || strcmp( note, "ab")==0 )
return 8;
else if( strcmp( note, "A" ) == 0 || strcmp( note, "a")==0 )
return 9;
else if( strcmp( note, "A#" ) == 0 || strcmp( note, "a#")==0||strcmp( note, "Bb" ) == 0 || strcmp( note, "bb")==0 )
return 10;
else if( strcmp( note, "B" ) == 0 || strcmp( note, "b")==0||strcmp( note, "Cb" ) == 0 || strcmp( note, "cb")==0 )
return 11;
else
{
printf("Not a Vaild Entry!!!\n");
printf("Please enter note AGAIN:");
scanf("%s",note);
convert(note);
return 0;
}
}