编程论坛's Archiver

ensonpan3927 发表于 2006-12-14 20:41

文本模式与图形模式的切换问题

   我以下的程序想实现的是在文本模式下,当输入字符a,返回图形模式执行函数fun1()函数,当输入b,则执行函数fun2(),这两个函数都是图形模式下的函数,但是我按照下面的程序调试不出来,也不知道对不对,各位知道的能不能帮改正提下啊?谢谢了<BR>   #include&lt;graphics.h&gt;<BR>    #include&lt;stdio.h&gt;<BR>    #include&lt;dos.h&gt;<BR>    #include&lt;stdlib.h&gt;<BR>    #include&lt;conio.h&gt;<BR>    main()<BR>    {<BR>     int gdriver=DETECT,gmode;<BR>     char c;<BR>     initgraph(&amp;gdriver,&amp;gmode,"");  /*初始化图形系统*/<BR>      cleardevice();<BR>     rect();/*调用画图函数*/<BR>     restorecrtmode();  /*文本模式下*/<BR>     printf("press a then fun1()and press b then fun2()");<BR>     <BR>     scanf("%c",c);<BR>     while(c==getchar())<BR>    {<BR>        if(c=='a')<BR>       {<BR>        fun1();<BR>        }<BR><BR>       if(c=='b')<BR>       {<BR>        fun2();<BR>       }<BR>    setgraphmode(getgraphmode()); /*返回图形模式*/<BR>    }    <BR>     <BR>     getch();<BR>     closegraph();<BR>   }

neverTheSame 发表于 2006-12-14 23:51

<P>在图形模式下,使用文本模式下的printf,是很不恰当的.<BR>应当用outtext()/outtextxy().<BR>要关闭图形模式,用closegraph()即可,就进入文本模式,<BR>再进入图形模式,又要 初始化图形系统.<BR></P>

ensonpan3927 发表于 2006-12-18 16:34

<P>各位懂的能不能给个确定的解决方法啊?</P>

一笔苍穹 发表于 2006-12-18 17:51

2楼说的就是方法啊,方法!=代码。

neverTheSame 发表于 2006-12-18 22:23

<BR>/*希望对楼主的学习有所帮助*/<BR><BR>#include&lt;stdio.h&gt;<BR>#include&lt;conio.h&gt;<BR>#include&lt;graphics.h&gt;<BR>/*两个图形函数*/<BR>int fun1(void);<BR>int fun2(void);<BR>void main(void)<BR>{<BR>   char ch;<BR>   clrscr();/*文本模式下的清屏*/<BR>   printf("Please input 'a'/'b'/'x':\n");/*'x' --&gt;exit*/<BR>   while(1)/*无限循环*/<BR>   {<BR>    ch=getchar();/*从标准输入设备输入一个字符,并按回车键*/<BR>    if('a'==ch)<BR>       fun1();<BR>     else if('b'==ch)<BR>       fun2();<BR>     else if('x'==ch)<BR>       break;<BR>     else<BR>     {<BR>       printf("Inputing was out of law\n");<BR>       fflush(stdin);/*清除,按回车键时带入的换行符*/<BR>       continue;<BR>     }<BR>   }<BR>}<BR>int fun1(void)<BR>{<BR>   int driver,mode;<BR>   driver=DETECT;<BR>   initgraph(&amp;driver,&amp;mode,"");<BR>   setbkcolor(14);<BR>   cleardevice();<BR>   getch();<BR>   fflush(stdin);/*清除,按任意键时,带回的字符*/<BR>   closegraph();<BR>}<BR>int fun2(void)<BR>{<BR>   int driver,mode;<BR>   driver=DETECT;<BR>   initgraph(&amp;driver,&amp;mode,"");<BR>   setbkcolor(RED);<BR>   cleardevice();<BR>   getch();<BR>   fflush(stdin);/*清除,按任意键时,带回的字符*/<BR>   closegraph();<BR>}

ensonpan3927 发表于 2006-12-19 00:18

<P>谢了,你可帮我大忙了!![em17]</P>

neverTheSame 发表于 2006-12-19 19:52

多多努力啊。

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.