-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject_phase_1.c
51 lines (47 loc) · 1.24 KB
/
project_phase_1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#include "beep.h"
int note_to_frequence();
int main()
{
int i, time[100];
double freq;
char note[1000][3], line[1000];
FILE *NoteFile;
NoteFile=fopen("NOTES.txt","r");
fgets(line, 20, NoteFile);
sscanf(line,"-N %s -d %d\n",¬e[0],&time[0]);
beep(392.00,750);
// reads all the notes from line 2 to 100 from NOTES.txt
for(i=1; i<=100; i++)
{
fgets(line, 20, NoteFile);
if(i==55 || i==60)
continue;
sscanf(line,"-n -N %s -d %d\n",¬e[i],&time[i]);
freq=note_to_frequence(note[i]);
beep(freq,time[i]+250);
}
fclose(NoteFile);
}
// gets the note and changes it to its frequence from note_frequence.txt file
int note_to_frequence(char x[3])
{
int i;
double freq[110];
char line[110], note[110][3],*result;
FILE *NoteFile2;
NoteFile2=fopen("note_frequence.txt", "r");
// it searchs the notes until it finds it and returns the frequence equal to it
for(i=0; i<109; i++)
{
fgets(line, 20, NoteFile2);
sscanf(line,"%s %lf\n",¬e[i],&freq[i]);
result=strstr(note[i],x);
if (result!=NULL)
{
return (freq[i]);
}
}
}