文本模式与图形模式的切换问题
我以下的程序想实现的是在文本模式下,当输入字符a,返回图形模式执行函数fun1()函数,当输入b,则执行函数fun2(),这两个函数都是图形模式下的函数,但是我按照下面的程序调试不出来,也不知道对不对,各位知道的能不能帮改正提下啊?谢谢了<BR> #include<graphics.h><BR> #include<stdio.h><BR> #include<dos.h><BR> #include<stdlib.h><BR> #include<conio.h><BR> main()<BR> {<BR> int gdriver=DETECT,gmode;<BR> char c;<BR> initgraph(&gdriver,&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> } <P>在图形模式下,使用文本模式下的printf,是很不恰当的.<BR>应当用outtext()/outtextxy().<BR>要关闭图形模式,用closegraph()即可,就进入文本模式,<BR>再进入图形模式,又要 初始化图形系统.<BR></P> <P>各位懂的能不能给个确定的解决方法啊?</P> 2楼说的就是方法啊,方法!=代码。 <BR>/*希望对楼主的学习有所帮助*/<BR><BR>#include<stdio.h><BR>#include<conio.h><BR>#include<graphics.h><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' -->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(&driver,&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(&driver,&mode,"");<BR> setbkcolor(RED);<BR> cleardevice();<BR> getch();<BR> fflush(stdin);/*清除,按任意键时,带回的字符*/<BR> closegraph();<BR>} <P>谢了,你可帮我大忙了!![em17]</P> 多多努力啊。页:
[1]
