Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- static char notes[] = "cdefgab";
- static char syllables[7][3] = { "do\0", "re\0", "mi\0", "fa\0", "so\0", "la\0", "ti\0" };
- int indexOf(char *src, char c);
- void notation(char *str);
- int main(int argc, char **argv) {
- int i = 0;
- char *str = NULL;
- if( argc >= 2 ) {
- for(i = 1; i < argc; ++i) {
- notation(argv[i]);
- }
- }
- return(0);
- }
- int indexOf(char *src, char c) {
- int p = -1;
- int i = 0, l = 0;
- if(src != NULL) {
- l = strlen(src);
- for(i = 0; i < l; ++i) {
- if( src[i] == c ) {
- p = i; break;
- }
- }
- }
- return(p);
- }
- void notation(char *str) {
- int i = 0, p = 0, b = 0, l1 = 0, l2 = strlen(notes);
- if( str != NULL ) {
- l1 = strlen(str);
- printf("solfege translation of [%s]\n", str);
- for(b = 0; b < l2; ++b) {
- printf("tonic - c = %s :", syllables[b]);
- for(i = 0; i < l1; ++i) {
- p = indexOf(notes, str[i]);
- if( p != -1 ) {
- printf(" %s", syllables[(p + b) % l2]);
- }
- }
- printf("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement