Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /*struct music
- {
- char note[2];
- int freq;
- };*/
- int findfrequency(char * note);
- void playMusic(char * music);
- void main()
- {
- /*struct music array[15];*/
- /*char * notes[15];
- int freq[15];
- notes[0]="D";
- notes[1]="E";
- notes[2]="F";
- notes[3]="G";
- notes[4]="A";
- notes[5]="B";
- notes[6]="c";
- notes[7]="d";
- notes[8]="e";
- notes[9]="f";
- notes[10]="g";
- notes[11]="a";
- notes[12]="b";
- notes[13]="c'";
- notes[14]="d'";
- freq[0]=294;
- freq[1]=330;
- freq[2]=370;
- freq[3]=392;
- freq[4]=440;
- freq[5]=494;
- freq[6]=554;
- freq[7]=587;
- freq[8]=659;
- freq[9]=740;
- freq[10]=784;
- freq[11]=880;
- freq[12]=988;
- freq[13]=1109;
- freq[14]=1175;
- int curFreq;
- char * curNote;
- printf("Enter note: ");
- scanf("%s", curNote);
- curFreq= findfrequency(curNote);
- if(curFreq==1)
- printf("Invalid Note\n");
- else
- printf("\n The frequency of that note is %d", curFreq);
- */
- char * music1 = "DEFGABcd";
- char * music2 = "D2E2F3GABcd";
- char * music3 = "defgabc'd'";
- printf("%s\n", music1);
- playMusic(music1);
- printf("%s\n", music2);
- playMusic(music2);
- printf("%s\n", music3);
- playMusic(music3);
- getchar();
- getchar();
- }//end main
- int findfrequency(char *note) //part 2
- {
- printf("%s", note);
- int freq[15];
- int i;
- char *notes[15];
- freq[0]=294;
- freq[1]=330;
- freq[2]=370;
- freq[3]=392;
- freq[4]=440;
- freq[5]=494;
- freq[6]=554;
- freq[7]=587;
- freq[8]=659;
- freq[9]=740;
- freq[10]=784;
- freq[11]=880;
- freq[12]=988;
- freq[13]=1109;
- freq[14]=1175;
- notes[0]="D";
- notes[1]="E";
- notes[2]="F";
- notes[3]="G";
- notes[4]="A";
- notes[5]="B";
- notes[6]="c";
- notes[7]="d";
- notes[8]="e";
- notes[9]="f";
- notes[10]="g";
- notes[11]="a";
- notes[12]="b";
- notes[13]="c'";
- notes[14]="d'";
- for(i=0;i<15;i++)
- {
- int match;
- match= strcmp(note, notes[i]);
- if(match==0)
- {
- return freq[i];
- }
- }
- return 1;
- }//end find freq
- void playMusic(char * music) //part 3
- {
- int freq;
- int i=0;
- int len = 0;
- int j=0;
- int compare;
- char *nums[9]; //array of the numbers, i.e the duration
- nums[0]="1";
- nums[1]="2";
- nums[2]="3";
- nums[3]="4";
- nums[4]="5";
- nums[5]="6";
- nums[6]="7";
- nums[7]="8";
- nums[8]="9";
- while(i!=NULL)
- {
- while(j!=NULL)
- {
- compare=strcmp(music+i, nums[j]); //compare current music note or duration with the number array
- if(compare==0)
- {
- printf("\t%s", nums[j]); //if its a number then print that number
- }//end if
- else
- {
- freq=findfrequency(music+i); //otherwise call findfrequency() and print that
- printf("%d", freq);
- }//end else
- j++;
- }//end inner fo
- i++;
- }//end for
- }
Add Comment
Please, Sign In to add comment