当前位置:首页 » 编程语言 » c语言coord

c语言coord

发布时间: 2025-10-03 22:07:37

1. c语言 CONSOLE_SCREEN_BUFFER_INFO 这个语句有什么用

COORD和CONSOLE_SCREEN_BUFFER_ INFO是wincon.h定义的控制台结构体类型,其原型如下:

//控制台窗口信息结构体
typedefstruct_CONSOLE_SCREEN_BUFFER_INFO{
COORDdwSize;//缓冲区大小
COORDdwCursorPosition;//当前光标位置
WORDwAttributes;//字符属性
SMALL_RECTsrWindow;//当前窗口显示的大小和位置
COORDdwMaximumWindowSize;//最大的窗口缓冲区大小
}CONSOLE_SCREEN_BUFFER_INFO;


举个简单的例子:

#include<windows.h>
#include<stdio.h>
#include<conio.h>
intmain(void)
{
HANDLEhOut;
CONSOLE_SCREEN_BUFFER_INFObInfo;//存储窗口信息
COORDpos={0,0};
//获取标准输出设备句柄
hOut=GetStdHandle(STD_OUTPUT_HANDLE);
//获取窗口信息
GetConsoleScreenBufferInfo(hOut,&bInfo);
printf(" Thesoulselectsherownsociety ");
printf("Thenshutsthedoor ");
printf("Onherdevinemajority ");
printf("Obtrudenomore ");
_getch();
//向窗口中填充字符以获得清屏的效果
FillConsoleOutputCharacter(hOut,'',bInfo.dwSize.X*bInfo.dwSize.Y,pos,NULL);
//关闭标准输出设备句柄
CloseHandle(hOut);
return0;
}

2. c语言的迷宫问题

//寻路_带权重_带障碍_最短_文件地图_不闪------wlfryq------//
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>

typedefstruct
{
intx;
inty;
}_PT;

_PTpt;
introw=0,col=0;

//设置CMD窗口光标位置
voidsetxy(intx,inty)
{
COORDcoord={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
//获取当前CMD当前光标所在位置
voidgetxy()
{
HANDLEhConsole=GetStdHandle(STD_OUTPUT_HANDLE);
COORDcoordScreen={0,0};//光标位置
CONSOLE_SCREEN_BUFFER_INFOcsbi;
if(GetConsoleScreenBufferInfo(hConsole,&csbi))
{
pt.x=csbi.dwCursorPosition.X;
pt.y=csbi.dwCursorPosition.Y;
}
}

typedefstruct
{
intx;
inty;
inttype;
intv;
}PT;

PT**s=NULL,stack[50],start,end,c;
intpos=0;

voidprt()
{
inti,j;
system("cls");
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
if(s[i][j].type==1)
{
printf("■");
}
elseif(i==end.x&&j==end.y)
{
printf("★");
}
elseif(i==c.x&&j==c.y)
{
printf("◎");
}
else
{
printf("");
}
}
printf(" ");
}
Sleep(500);
}

voidstack_in(PTa)
{
stack[pos++]=a;
}

PTstack_out()
{
inti;
PTt;
t=stack[0];
for(i=0;i<pos-1;i++)
{
stack[i]=stack[i+1];
}
pos--;
returnt;
}

voidfun()
{
PTa;
intx,y,v;
while(1)
{
if(pos==0)
{
break;
}
a=stack_out();
x=a.x;
y=a.y;
if(x==start.x&&y==start.y)
{
break;
}
v=s[x][y].v;
if(x-1>=0&&s[x-1][y].type==0&&(s[x-1][y].v==-1||s[x-1][y].v>v+1))
{
s[x-1][y].v=v+1;
stack_in(s[x-1][y]);
}
if(x+1<=row-1&&s[x+1][y].type==0&&(s[x+1][y].v==-1||s[x-1][y].v>v+1))
{
s[x+1][y].v=v+1;
stack_in(s[x+1][y]);
}
if(y-1>=0&&s[x][y-1].type==0&&(s[x][y-1].v==-1||s[x-1][y].v>v+1))
{
s[x][y-1].v=v+1;
stack_in(s[x][y-1]);
}
if(y+1<=col-1&&s[x][y+1].type==0&&(s[x][y+1].v==-1||s[x-1][y].v>v+1))
{
s[x][y+1].v=v+1;
stack_in(s[x][y+1]);
}
}
}

voidgo(intx,inty)
{
printf(" 按任意键开始 ");
getchar();
intv;
while(1)
{
if(x==end.x&&y==end.y)
{
setxy(0,y+2);
printf("end....");
return;
}
v=s[x][y].v;
if(v==0)
{
return;
}
if(x-1>=0&&s[x-1][y].v==v-1)
{
c=s[x-1][y];
setxy(y*2,x);
x=x-1;
printf("");
setxy(y*2,x);
printf("◎");
Sleep(500);
continue;
}
elseif(x+1<=row-1&&s[x+1][y].v==v-1)
{
c=s[x+1][y];
setxy(y*2,x);
x++;
printf("");
setxy(y*2,x);
printf("◎");
Sleep(500);
continue;
}
elseif(y-1>=0&&s[x][y-1].v==v-1)
{
c=s[x][y-1];
setxy(y*2,x);
y--;
printf("");
setxy(y*2,x);
printf("◎");
Sleep(500);
continue;
}
elseif(y+1<=col-1&&s[x][y+1].v==v-1)
{
c=s[x][y+1];
setxy(y*2,x);
y++;
printf("");
setxy(y*2,x);
printf("◎");
Sleep(500);
continue;
}
}
printf(" returngo ");
system("pause");
}

voidGetMapFromFile()
{
inti,j,x,y,len;
charch[50]={''};
FILE*fp=fopen("e:\map1.txt","r");
if(fp==NULL)
{
printf("openfilefailed. ");
return;
}
x=0;

while(!feof(fp))
{
fgets(ch,50,fp);
row++;
}
col=strlen(ch);
fseek(fp,0L,SEEK_SET);
while(!feof(fp))
{
fgets(ch,50,fp);
if(s==NULL)
{
len=strlen(ch);
for(i=len-1;i>0;i--)
{
if(ch[i]!='0'&&ch[i]!='1')
{
ch[i]='';
}
else
{
break;
}
}
len=strlen(ch);
s=(PT**)malloc(sizeof(PT*)*row);
for(j=0;j<len;j++)
{
*(s+j)=(PT*)malloc(sizeof(PT)*len);
}
}
y=0;
for(i=0;i<len;i++)
{
s[x][y].type=ch[i]-48;
s[x][y].x=x;
s[x][y].y=y;
s[x][y].v=-1;
y++;
}
x++;
}
start=s[row-2][1];
end=s[row-2][len-2];
fclose(fp);
}

intmain()
{
GetMapFromFile();
inti,j;
intx,y;
x=end.x;
y=end.y;
s[x][y].v=0;
stack_in(end);
fun();
c=start;
prt();
go(start.x,start.y);
return0;
}

3. C语言中 gotoxy有什么作用

是光标定位函数,在windows.h中,不过还得写一下函数,以下参考:

#include<windows.h>
intGotoxy(intx,inty)
intGotoxy(intx,inty)//定位光标位置
{
HANDLEhandle;//定义句柄变量handle
COORDcoord;//定义结构体coord(坐标系coord)
coord.X=x;//横坐标x
coord.Y=y;//纵坐标y
handle=GetStdHandle(STD_OUTPUT_HANDLE);//获取控制台输出句柄(值为-11)
SetConsoleCursorPosition(handle,coord);//移动光标
}
intmain()
{
Gotoxy(x,y);//x为横坐标,即为所在行数;y为纵坐标,即为所在列数
}
热点内容
如何查看账户密码 发布:2025-10-03 23:51:41 浏览:739
exe编译后怎么存储 发布:2025-10-03 23:33:51 浏览:83
javaforremove 发布:2025-10-03 23:32:11 浏览:745
机顶盒的账户密码是多少 发布:2025-10-03 23:15:47 浏览:117
手机wifi加密设置方法 发布:2025-10-03 23:06:43 浏览:699
云服务器远程 发布:2025-10-03 23:01:21 浏览:711
androidtcp连接 发布:2025-10-03 22:52:49 浏览:999
mysqlphp查询语句 发布:2025-10-03 22:50:58 浏览:436
linuxtxt打开 发布:2025-10-03 22:50:46 浏览:330
java同步和异步的区别 发布:2025-10-03 22:45:29 浏览:764