求帮看看哪里有问题,为什么一直定义不了
#include<stdio.h>
#include<stdlib.h>
int main()
{
int x1 =10,y1 = 1,x2 = x1 + 26 + 2,y2 = y1 + 20; int i;
char c;
system("mode con cols = 80 lines = 22");
HideCursor(0);
DrawRectangle(x1,y1,x2,y2);
GotoXY(x1+2,y2-1);
printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); do
{
c=rand()%26+'A' ;
for(i=y1+1;i<y2-1;i=i+1)
{
GotoXY(x1+c-'A'+2,i);
printf("%c",c);
Sleep(100);
GotoXY(x1+c-'A'+2,i);
printf(" ");
}
GotoXY(x1+c-'A'+2,i);
printf("=");
Sleep(200);
GotoXY(x1+c-'A'+2,i);
printf("%c",c);
}
while(kbhit()==0);
return;
}
c:\Users\LENOVO\Desktop\学习\信息\例6.37.cpp [Error] 'HideCursor' was not declared in this scope10
27 C:\Users\LENOVO\Desktop\学习\信息\例6.37.cpp [Error] 'DrawRectangle' was not declared in this scope11
18 C:\Users\LENOVO\Desktop\学习\信息\例6.37.cpp [Error] 'GotoXY' was not declared in this scope20
13 C:\Users\LENOVO\Desktop\学习\信息\例6.37.cpp [Error] 'Sleep' was not declared in this scope26
12 C:\Users\LENOVO\Desktop\学习\信息\例6.37.cpp [Error] 'Sleep' was not declared in this scope30
14 C:\Users\LENOVO\Desktop\学习\信息\例6.37.cpp [Error] 'kbhit' was not declared in this scope31
2 C:\Users\LENOVO\Desktop\学习\信息\例6.37.cpp [Error] 'return0' was not declared in this scope
应该要在头文件加一个#include<windows.h>吧
还有就是你的主函数最后要return 0
再次修改:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
#define map_mode "■"
void HideCursor() //隐藏光标
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut, &cci);
cci.bVisible = FALSE;
SetConsoleCursorInfo(hOut, &cci);
}
void GotoXY(int x, int y) //光标移动到x,y位置
{
COORD pos = { x,y };
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 获取标准输出设备句柄
SetConsoleCursorPosition(hOut, pos); //两个参数分别是指定哪个窗体,具体位置
}
void DrawRectangle(int x1, int y1, int x2, int y2)
{
int i;
for (i = x1; i < x2 ; i += 2) {
GotoXY(i, y1);
printf(map_mode);
GotoXY(i, y2);
printf(map_mode);
}
for (i = y1; i < y2 + 1; i++) {
GotoXY(x1, i);
printf(map_mode);
GotoXY(x2, i);
printf(map_mode);
}
}
int main()
{
int x1 = 10, y1 = 1, x2 = x1 + 26 + 2, y2 = y1 + 20;
int i;
char c;
system("mode con cols=50 lines=25");
system("color 0A"); //背景黑色 字体绿色
HideCursor();
DrawRectangle(x1, y1, x2, y2);
GotoXY(x1 + 2, y2 - 1);
printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
do{
c = rand() % 26 + 'A';
for (i = y1 + 1; i < y2 - 1; i = i + 1)
{
GotoXY(x1 + c - 'A' + 2, i);
printf("%c", c);
Sleep(100);
GotoXY(x1 + c - 'A' + 2, i);
printf(" ");
}
GotoXY(x1 + c - 'A' + 2, i);
printf("=");
Sleep(200);
GotoXY(x1 + c - 'A' + 2, i);
printf("%c", c);
} while (kbhit() == 0);
return 0;
}