Home > Back-end >  VC realize music function
VC realize music function

Time:09-16

For help bosses

Display error
The error C2373: 'time' : redefinition; The company type modifiers
C: \ program files \ Microsoft visual studio (x86) \ vc98 \ include \ time h (156) : see declaration of 'time'

Procedure is as follows:
# include "stdio.h"
# include "conio. H"
# include "stdlib. H"
# include "string. H"
# include "time. H"
H # include "Windows."
Int speed=1, the time;
Void menu (void);
Void sound1 (int freq, int time);
Void pause (int time);
Void xueronghua (void);
Void xiaoxingxing (void);
Void happybirthday (void);
Void the display (char * x);
Int main (void)
{
menu();
return 0;
}
Void menu (void)
{
Int sel.
Do
{
System (" CLS ");
Printf (" \ n \ t \ t * * * * * * * * welcome to songs on demand system * * * * * * * * \ n \ n ");
Printf (" \ t \ \ t t1. Edelweiss \ n ");
Printf (" \ t \ \ t t2. Little stars \ n ");
Printf (" \ t \ \ t t3. HAPPY BIRTHDAY \ n ");
Printf (" \ t \ \ t t0. Exit system \ n ");
Printf (" \ n \ n \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ");
Printf (" \ n please select (0-3) \ n ");
The scanf (" % d ", & amp; Sel);
The switch (sel) {
Case 1: xueronghua (); break;
Case 2: xiaoxingxing (); break;
Case 3: happybirthday (); break;
Case: 0 exit (1);
}
}
while(1);
}
Edelweiss void xueronghua (void)/* always */
{
Char * jp="iddgwwwqqgfffddddfghhhggg DDGWWWQQGFFFDDGGHJQQQQQWPGGJHGDDGQQQ HHQWWQJJJGGGDDGWWWQQGFFFDDGGHJQQQQQQ";
Speed=2;
Time=4 * speed;
//gotoxy (40, 20);
Printf (" \ t \ t \ n enjoy song: edelweiss ");
Printf (" \ n \ t \ \ t t edelweiss, edelweiss, open early in the morning to meet me, ");
Printf (" \ n \ t \ \ t t small and white, clean and bright, happy to me shaking, ");
Printf (" \ n \ t t \ \ t like Snow White flowers, I wish you happiness, forever bloom, ");
Printf (" \ n \ t \ \ t t edelweiss, edelweiss, bless my hometown forever, \ n ");
The display (jp);
Printf (" edelweiss appreciate over ");
Printf (" press any key to return to the main menu ");
Getch ();
menu();
}
Void xiaoxingxing (void)/* always */
twinkle twinkle little star{
Char * jp="oaagghhggffddssaaggffddssggffddssaagghhggffddssaaaagghhggffddssaaggffddssggffddssaagghhggffddssaa";
Speed=2;
Time=4 * speed;
//gotoxy (40, 20);
Cprintf (please appreciate the song: "little star");
Printf (" \ n \ t \ \ t t twinkle twinkle twinkle little star, the sky is little star, ");
Printf (" \ n \ t \ \ t t hang put the light in the sky, as if thousands of small eyes, ");
Printf (" \ n \ t \ \ t t the sun sink slowly to the west, the crow flocks of home, ");
Printf (" \ n \ t \ \ t t stars blinked his small eyes, until morning, bright \ n ");
The display (jp);
Cprintf (" at the end of little stars enjoy ");
Cprintf (" press any key to return to the main menu ");
Getch ();
menu();
}
Void happybirthday (void)/* happy birthday song */
{
Char * jp="ippppbbnnbbaammmmbbnnbbssaaaabbggddaammmhfddaassaaappp";
Speed=1;
Time=4 * speed;
//gotoxy (40, 20);
Cprintf (please appreciate the song: "HAPPY BIRTHDAY");
Printf (" \ n \ t \ \ t tHAAPY BIRTHDAY TO YOU, ");
Printf (" \ n \ t \ \ t tHAAPY BIRTHDAY TO YOU, ");
Printf (" \ n \ t \ \ t tHAAPY BIRTHDAY TO YOU, ");
Printf (" \ n \ t \ \ t tHAAPY BIRTHDAY TO YOU. \ n ");
The display (jp);
//gotoxy (40, 20);
Cprintf (" HAPPY BIRTHDAY to appreciate over ");
Cprintf (" press any key to return to the main menu ");
Getch ();
menu();
}
Void the display (char * qm)/* * play function/
{
Int I, freq.
While (* qm++!='\ 0') {
i=1;
The switch (* qm) {
Case: 'k' time=1 * speed; i=0; break;
Case 'l' : time=2 * speed; i=0; break;
Case 'I' : time=4 * speed; i=0; break;
Case: 'o' time=6 * speed; i=0; break;
Case: 'p' pause (time); i=0; break;
Case 'a' : freq=523; break;
Case 's' : freq=587; break;
Case 'd' : freq=659; break;
Case: 'f' freq=698; break;
Case: 'g' freq=784; break;
Case 'h' : freq=880; break;
Case 'j' : freq=988; break;
Case: 'z' freq=262; break;
Case 'x' : freq=294; break;
Case 'c' : freq=330; break;
Case 'v' : freq=349; break;
Case 'b' : freq=392; break;
Case 'n' : freq=440; break;
Case 'm: freq=494; break;
Case: 'q' freq=1047; break;
Case 'w' : freq=1175; break;
Case 'e' : freq=1319; break;
Case: 'r' freq=1397; break;
Case the 't' : freq=2568; break;
Case: 'y' freq=1760; break;
Case 'u' : freq=1976; break;
Default: I=0; break;
}
If (I)
Sound1 (freq, time);
}
}
Void sound1 (int freq, int time)/* */voice function
{
int n;
MessageBeep (freq);
N=time + clock ();
While (n> Clock ());
MessageBeep (0);
}
Void pause (int time)/* */pause function
{
int n;
N=time + clock ();
While (n> Clock ())
MessageBeep (0);
}






CodePudding user response:

To a variable, only one statement, reputation for many times, even if the declared type, same is also wrong,
The function, can be directly in the "prototype" statement,
https://blog.csdn.net/weixin_43641971/article/details/88119496

CodePudding user response:

Time is the key word, is a function, you change, don't use time as a variable name

CodePudding user response:

Simple - Soft references 2 floor response:
time is the key word, is a function, you change, don't use time as a variable name

After changed, the program can run without error, but not play songs sound
  • Related