谁能帮助我纠正这个程序的编写并运行这个程序?

标签 c

描述:直接通过电脑内置扬声器播放音乐

我是编程新手,自学了两个月的 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);
}
*/

最佳答案

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

我注意到 Beep() 函数没有在任何地方定义。我想象它曾一度在 conio.h 文件中定义,但 Microsoft 在过渡到 Windows 期间放弃了它。

关于谁能帮助我纠正这个程序的编写并运行这个程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3493986/

相关文章:

c - 将 int 类型转换为 char,然后搜索数组

c - 寻找 nCr 值

c++ - g++错误:word64没有命名类型

c - 打破严格的别名并摆脱它

c - 程序不响应终端发送的 linux 信号而无需在终端上连续打印

c - C 中计数和计数位的输出不正确

c - 避免堆栈溢出(C 中的迷宫生成器)

c - 为什么我的结构定义不完整?

c++ - C/C++ - 计算函数调用中的参数

c - 在C中动态分配内存给常量char指针?