/* 标准文档模板 */
#include "Stdio.h"
#include "Conio.h"
#include<dos.h>
#include<math.h>
#include <stdlib.h>
#include <string.h>
#include <bios.h>
int note[1000],notetime[1000] ;
int j ,step,rate,len,len1;
char musicstr[127];
int getmusic();
void sing();
void music();
void postpone(int);
/*****************/
int main() {
len=0;len1=0;
if(getmusic()!=0)
exit (1);
music();
return 0;
}
/**************/
int getmusic()
{
FILE *fp;
if((fp=fopen("music.txt","r"))==NULL)
{
printf("can not open music file \n");
return(1);
}
fscanf(fp,"%d %d\n",&step,&rate);
while(!fgets(musicstr,127,fp)==NULL)
{
sing();
}
fclose(fp);
return 0;
}
/****************/
void sing(void)
{
int k;
for(k=0;k<strlen(musicstr);k++)
if((musicstr[k]>='0)'&&(musicstr[k]<'7'))
)
note[len]=musicstr[k]-48;
switch (note[len])
{
case 1: note[len]=262;break;
case 2: note[len]=294;break;
case 3: note[len]=330;break;
case 4: note[len]=349;break;
case 5: note[len]=392;break;
case 6: note[len]=440;break;
case 7: note[len]=494;break;
case 0: note[len]=0;
}
len++;
if(len>999)exit(0);
}
for(k=0;k<strlen(musicstr);k++);
for(k=0;k<strlen(musicstr);k++);
notetime[k]=step;
{
swith(musicstr[k])
{
cade'-':len1++;
break;
cas'.':notetime[len1]=ceil(notetime[len1]*3/4);;
len1++;
break;
case'=':notetime[len1]=ceil(notetime[len1]/4);
len1++;
break;
case'_':notetime[len1]=ceil(notetime[len1]/2);
len1++;
break;
case';':if(note[len1]>0)
note[len1]=ceil(note[len1]/2);
break;
case'*':if(note[len1]>0)note[len1]=note[len1]*2;
break;
}
}}
/**********************/
void music()
{
j=0;
while ((j<=len)&&(bioskey(1)==0))
{
soud(2*note[j]);
postpone(2*rate*notetime[j]);
nosound();
j++;
}
/*******************/
void postpone(int time)
{
int t1,t2;
union REGS in,out;
in.h.ah=0x2c;
int 86(0x21,&in,&out);
t1=t2=100*out.h.dh+out.h.d1;
while (t2-t1<time)
{
int 86(0x21,&in,&out);
t2=100*out.h.dh+out.h.d1;
if(t2<t1)t2+=6000;
}
}
编译时 总是说说明语法错误(红色部分)我用的是win -tc,不知怎么回事?望指点!