首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

C图形编程有关问题 帮忙解决下

2012-04-02 
C图形编程问题 大虾帮忙解决下啊问题1:程序代码如下#includeconio.h #includestdio.h intmain(){struc

C图形编程问题 大虾帮忙解决下啊
问题1:

程序代码如下

#include   "conio.h "
#include   "stdio.h "
int   main()
{
struct   text_info   current;
textmode(C80);
textbackground(1);
textcolor(13);
window(1,5,70,20);
clrscr();
cputs( "Current   information   of   window\r\n ");
gettextinfo(&current);
cprintf( "Left   corner   of   window   is   %d,%d\r\n ",current.winleft,current.wintop);
cprintf( "Right   corner   of   window   is   %d,%d\r\n ",current.winright,current.winbottom);
cprintf( "Text   window   attribute   is   %d\r\n ",current.attribute);
cprintf( "Text   window   normal   attribute   %d\r\n ",current.normattr);
cprintf( "Current   Video   mode   is   %d\r\n ",current.currmode);
cprintf( "Window   height   and   width   is   %d,%d\r\n ",current.screenheight,current.screenwidth);
cprintf( "Row   cursor   pos   is   %d,Coloumn   pos   is   %d\r\n ",current.cury,current.curx);
getchar();
return   1;
}

作用是现实当前显示器信息。在TC中编译、连接、运行正常,可是在VC++和Dev-C++却编译不通过。为什么?

问题2:

代码如下

#include   "graphics.h "
main()
{
int   graphdriver=CGA;
int   graphmode=CGAC0,x;
initgraph(&graphdriver,&graphmode, " ");
cleardevice();
for(x=20;x <=300;x+=16)
{
      putpixel(x,20,1);
      putpixel(x+4,20,2);
}
getch();
closegraph();
}
在TC中运行屏幕现实“BGI   Error:   Graphics   not   initalized   (use   ‘initgraph’   )”。可是我已经把GRAPHICS.LIB拷贝到运行目录下。为什么?

问题3:

代码片断如下

……
char   *ch2= "China. ";
*(ch2+2)= '\0 ';
printf( "%s ",ch2);
……

为什么在TC中运行无误,可是在VC++2005里面却出错。错误提示信息:“0x00411b03   处未处理的异常:   0xC0000005:   写入位置   0x0041565a   时发生访问冲突”。为什么?

PS:谢谢哪个大虾帮我解决下啊~~~~


[解决办法]
TC使用自己的图形驱动库,你要是想在VC或者别的环境中使用图形,就使用系统级别的图形支持函数,或者IDE提供的图形库,例如直接使用VC的MFC或者系统的图形API。

不同环境的程序要移植以后才能编译使用


[解决办法]
正如doubhor()说的,TC和VC使用的不是一套图形库.

char *ch2= "China. ";
*(ch2+2)= '\0 ';
printf( "%s ",ch2);
系统好象控制内存,不允许使用类似*(ch2+2)= '\0 ';这个我是感觉,没有权威性

[解决办法]
char *ch2= "China. "

"china "是在靜態存儲區, 值不能被修改.

热点排行