任何人都可以帮我纠正我对这个程序的写作并运行这个程序吗?

时间:2010-08-16 14:17:39

标签: c

说明:直接将音乐播放到PC的内置扬声器

我是编程的新手,有两个月的C编程自学。任何人都可以帮我纠正我对这个程序的写作并运行这个程序吗?

#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<windows.h>


int CursoR(int CRx,int CRy){
 COORD CursorPosition;

 CursorPosition.X=CRx;
 CursorPosition.Y=CRy;
 return SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),CursorPosition);
}
int __CursoR(int CRx,BOOL Bool){
 CONSOLE_CURSOR_INFO CursorInfo;

 CursorInfo.bVisible = Bool;
 CursorInfo.dwSize = CRx;

 return SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &CursorInfo);
}
int LayouT(int LYx,int LYy){
 COORD Size;

 Size.X = LYx;
 Size.Y = LYy;

 return SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), Size);
}
int _ColoR(int Clr){
 return SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),Clr);
}
int CLS(){
 int max=9999,max1=9999;
 for(auto int C=0;C<=max;C++){
  for(auto int C1=0;C1<=max1;C1++){
   CursoR(C1,C);printf(" ");
   if(CursoR(C1,C)==0){ max1=C1-1; }
  }
  C1=0;
  if(CursoR(C1,C)==0){
   CursoR(0,0);puts(" ");break; }
 }
 return 0;
}

struct tm *local(){
 time_t t;
 t = time(NULL);

 return localtime(&t);
}

const char MDay[][12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
const char Day[][12]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int Md=local()->tm_mon;
int Dy=local()->tm_wday;

FILE *srcF;

void Display(){
 {
  _ColoR(0x88+0x0256);
  CursoR(54,5);
  printf("",fputchar(14));
  _ColoR(0x88+0x0253);
 }
 printf("\n ");
 for(int e=0;e<108;e++)printf("",fputchar(220));

 printf("\n\n\n ");
 for(e=0;e<108;e++)printf("",fputchar(220));

 printf("\n ============================================================================================================\n");
 _ColoR(0x88+0x0256);
 printf("     1    2    3    4    5    6    7    1    2    3    4    5    6    7    1    2    3    4    5    6    7");
 _ColoR(0x88+0x0253);
 printf("\n ============================================================================================================\n");

 for(e=0;e<13;e++)
 {
  if(e!=12)_ColoR(0x88+0x0253);
  printf(" ");_ColoR(0x88+0x0213);

  printf("º");
  for(int e0=0;e0<21;e0++)printf("º    ");
  printf("ºº\n");
 }
 printf(" ");
 for(e=0;e<108;e++)printf("",fputchar(223));
 for(e=11;e<19;e++)
 {
  for(int e0=1;e0<108;e0+=15){
   CursoR(e0,e);printf("ººº");
  }
 }

 {
  CursoR(37,23);
  printf(".SoftEng2010.Copyright (c) 2019-2020.");
 }
}

void NoteSaveText(){
 fprintf(srcF,"Note: You have previous pattern that was yet kept by other name. you can save it now to avoid overwrite by next changes\n");
 fprintf(srcF,"Copy all melody key at the bellow and then paste in the BeepMusic boxes to make a melody.\n");
 fprintf(srcF,"Or you can close it to create a new melody key:\n\n");
 fprintf(srcF,"Last created: %d:%d:%d / %s, %s %d, %d\n\n",local()->tm_hour,local()->tm_min,local()->tm_sec,Day[Dy],MDay[Md],local()->tm_mday,local()->tm_year+1900);
 fprintf(srcF,"\n\n    ...MELODY KEY>>>> \n\n\n");
}

void LetsPlay(){
 if(!(rename("BeepMusic.SE0","BeepMusic.txt"))){
  system("BeepMusic.txt");
  rename("BeepMusic.txt","BeepMusic.SE0");
 }
 srcF=fopen("BeepMusic.SE0","w+");
 NoteSaveText();

 char Tone;
 int Oktaf=0,C,B,R=0,H=0,h=0,L=100,n=0;
 int e,Clr=0x0020,Clr0=0x01;

 Display();

 CursoR(1,0);puts("If you finished play it, press Esc to close & save all a melody key");
 do{
  n++;
  CursoR(53,24);Tone=getche();
  if((fputchar(27))!=(fputchar(Tone)))fprintf(srcF,"%c",Tone);
  if(n%70==0)fprintf(srcF,"\n");

  Tone=tolower(Tone);

  if(Tone<='9' && Tone>='0')
  {
   Oktaf=-1;
   for(char ch='0';ch<=Tone;ch++)Oktaf++;
   Oktaf=Oktaf*1000;
  }

  if(Tone=='l')
  {
   CursoR(53,24);Tone=getche();
   L=-70;
   for(char ch='0';ch<=Tone;ch++)L+=40;
   if(Tone=='0')L=100;
  }

  if((fputchar(27))==(fputchar(Tone))){
   fclose(srcF);
   exit(0);
  }

  if(Tone=='-')
  {
   h++;
   if(h%2!=0)
    { H=25; CursoR(103,6); printf("::1/2"); }
   else
    { H=0;  CursoR(103,6); printf("::1  "); }
  }

  _ColoR(0x88+0x0253);
  switch(Tone)
  {
   case 'q':
    C=5,B=40;
   break;
   case 'w':
    C=10,B=80;
   break;
   case 'e':
    C=15,B=110;
   break;
   case 'r':
    C=20,B=140;
   break;
   case 't':
    C=25,B=170;
   break;
   case 'y':
    C=30,B=230;
   break;
   case 'u':
    C=35,B=280;
   break;
   //////////////
   case 'a':
    C=40,B=300;
   break;
   case 's':
    C=45,B=350;
   break;
   case 'd':
    C=50,B=400;
   break;
   case 'f':
    C=55,B=450;
   break;
   case 'g':
    C=60,B=500;
   break;
   case 'h':
    C=65,B=550;
   break;
   case 'j':
    C=70,B=600;
   break;
   //////////////
   case 'z':
    C=75,B=700;
   break;
   case 'x':
    C=80,B=750;
   break;
   case 'c':
    C=85,B=800;
   break;
   case 'v':
    C=90,B=850;
   break;
   case 'b':
    C=95,B=900;
   break;
   case 'n':
    C=100,B=950;
   break;
   case 'm':
    C=105,B=1000;
   break;
  }

  {
   _ColoR((Clr0++)+(Clr+=0x0001));
   CursoR(C,20);printf(" ");
   Beep(B+Oktaf+H,L);
   _ColoR(0x88+0x0213);
   CursoR(C,20);printf(" ");
  }

  if(R==5)R=0;
  _ColoR((Clr0++)+(Clr+=0x0001));

  for(e=0+(R++);e<105+R;e+=5){
   CursoR(e,0);printf("    ",fputchar(14));
   CursoR(0,0);printf("    ");
  }

  {
   CursoR(106,1);printf("    ");
   _ColoR(0x88+0x0256);
  }

  CursoR(52,6);printf("%d Hz  ",B+Oktaf+H);
  CursoR(2,6);printf("%d/9::",Oktaf/1000);
  CursoR(2,3);printf("Tempo: %d/330  ",L);
 }while(1);
}

int main(void)
{
 SetConsoleTitle("BeepMusic.SoftEng 2010.");
 _ColoR(0x88+0x0253);
 for(int n=1;n<=20;n++){
  Sleep(60);
  MoveWindow(GetForegroundWindow(),180,200,900,15*n,1);
 }
 LayouT(110,25);
 CLS();
 __CursoR(1,FALSE);

 if(WINVER >= 0x0400 && system("cls")==0){
  LetsPlay();
  return 0x00;
 }
 else{
  MoveWindow(GetForegroundWindow(),0,0,0,0,1);
  MessageBox(GetForegroundWindow(), "Sorry, !!!  ONLY NEWEST WINDOWS VERSION  !!!     ","BeepMusic",MB_ICONSTOP);
  return 0x01;
 }
return 0;
}


/*
int __LayouT(int LYx,int LYy){
 _CONSOLE_SCREEN_BUFFER_INFO inFo;

 inFo.dwCursorPosition.X=40;
 inFo.dwCursorPosition.Y=40;

 inFo.dwMaximumWindowSize.X=200;
 inFo.dwMaximumWindowSize.Y=300;

 inFo.dwSize.X=60;
 inFo.dwSize.Y=60;

 inFo.srWindow.Bottom=500;
 inFo.srWindow.Left=100;
 inFo.srWindow.Right=400;
 inFo.srWindow.Top=100;

 inFo.wAttributes=BACKGROUND_GREEN+FOREGROUND_BLUE;

 return GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&inFo);
}
*/

1 个答案:

答案 0 :(得分:0)

如果你告诉我们你遇到了什么问题会有所帮助。

我注意到Beep()函数没有在任何地方定义。我认为它曾经在conio.h文件中定义了一次,但是在转换到Windows期间,微软放弃了它。