Advertisement
Guest User

Untitled

a guest
Feb 14th, 2013
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. static char notes[] = "cdefgab";
  6. static char syllables[7][3] = { "do\0", "re\0", "mi\0", "fa\0", "so\0", "la\0", "ti\0" };
  7.  
  8. int indexOf(char *src, char c);
  9. void notation(char *str);
  10.  
  11. int main(int argc, char **argv) {
  12.    int i = 0;
  13.    char *str = NULL;
  14.    if( argc >= 2 ) {
  15.       for(i = 1; i < argc; ++i) {
  16.          notation(argv[i]);
  17.       }
  18.    }
  19.    return(0);
  20. }
  21.  
  22. int indexOf(char *src, char c) {
  23.    int p = -1;
  24.    int i = 0, l = 0;
  25.    if(src != NULL) {
  26.       l = strlen(src);
  27.       for(i = 0; i < l; ++i) {
  28.          if( src[i] == c ) {
  29.             p = i; break;
  30.          }
  31.       }
  32.    }
  33.    return(p);
  34. }
  35.  
  36. void notation(char *str) {
  37.    int i = 0, p = 0, b = 0, l1 = 0, l2 = strlen(notes);
  38.    if( str != NULL ) {
  39.       l1 = strlen(str);
  40.       printf("solfege translation of [%s]\n", str);
  41.       for(b = 0; b < l2; ++b) {
  42.          printf("tonic - c = %s :", syllables[b]);
  43.          for(i = 0; i < l1; ++i) {
  44.             p = indexOf(notes, str[i]);
  45.             if( p != -1 ) {
  46.                printf(" %s", syllables[(p + b) % l2]);
  47.             }
  48.          }
  49.          printf("\n");
  50.       }
  51.    }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement