当前位置: 代码迷 >> C语言 >> 帮忙把此代码优化下,谢谢!
  详细解决方案

帮忙把此代码优化下,谢谢!

热度:297   发布时间:2008-01-16 14:08:41.0
帮忙把此代码优化下,谢谢!
提示: 作者被禁止或删除 内容自动屏蔽
2008-01-16 06:08:41
sunkaidong

来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4493
专家分:141
注 册:2006-12-28
  得分:0 
你的里面还有错呢,你是不是还需要GRAPHIC.H呢?
----------------解决方案--------------------------------------------------------
提示: 作者被禁止或删除 内容自动屏蔽

坚持到底
2008-01-16 08:24:50
xianshizhe111

等 级:新手上路
帖 子:1451
专家分:0
注 册:2007-12-8
  得分:0 
/*这个可以*/ /*真不易呀!(我没有帮你做图形界面的那样就得全改了没时间了*/
#include"stdio.h"
#include"conio.h"
#define Esc 27
#define Enter 13
#define upkey 72
#define downkey 80
#define Menu_x 35
#define Menu_y 12

void Fream()
{
textcolor(GREEN);
gotoxy(22,11);
cprintf("**********************************\n");
gotoxy(22,12);
cprintf("*                                *\n"); /*星号位子有变化自己动一下*/
gotoxy(22,13);
cprintf("*                                *\n");
gotoxy(22,14);
cprintf("*                                *\n");
gotoxy(22,15);
cprintf("**********************************\n");

}


void EnterFace(int choice)
{
int w,h,x,y;
x=Menu_x;
y=Menu_y;
textbackground(0);
clrscr();
Fream();
gotoxy(x,y);
if(choice==Menu_y)
textcolor(RED);
else
textcolor(WHITE);
cprintf("Enter");
gotoxy(x,y+2);
if(choice==Menu_y+2)
textcolor(RED);
else
textcolor(WHITE);
cprintf("Exit");
}

void main()
{
char key,password1[10],name1[10];
int i=0,old_x,old_y,choice,k=0;
struct user
{char *password;
char *name;
char *sex;
char *age;
};struct user User1;
User1.password="33467";
User1.name="yuewei";

old_x=Menu_x;
old_y=Menu_y;
choice=old_y;

EnterFace(old_y);
do
{
EnterFace(choice);
kbhit();
key=getch();
switch(key)
{
case upkey:
if(old_y==Menu_y)
choice=Menu_y+2;
else
choice=old_y-2;
old_y=choice;
EnterFace(choice);
break;
case downkey:
if(old_y==Menu_y+2)
choice=old_y-2;
else choice=old_y+2;
old_y=choice;
EnterFace(choice);
break;
case Enter:
switch(choice)
{case Menu_y:
for(i=0;i<3;i++)
{
Fream();
textcolor(WHITE);
gotoxy(old_x,old_y);
cprintf("User Name");
gotoxy(old_x,old_y+2);
while((name1[k]=getch())!='\r')
{    cprintf("*");
     k++;}
name1[k]='\0';
k=0;
Fream();
textcolor(WHITE);
gotoxy(old_x,old_y);
cprintf("Password");
gotoxy(old_x,old_y+2);

while((password1[k]=getch())!='\r')
{
cprintf("*");
    k++;}

password1[k]='\0';
if(strcmp(password1,User1.password)==0&&strcmp(name1,User1.name)==0)
{
Fream();
textcolor(WHITE);
gotoxy(old_x,old_y);
cprintf("Welcome");
gotoxy(old_x-10,old_y+2);
cprintf("press any key back");
getch();
break;
}
else
{
Fream();
textcolor(WHITE);
gotoxy(old_x,old_y);
cprintf("Error");
gotoxy(old_x-10,old_y+2);
cprintf("Password any key to continue.");
getch();
}
}
if(i==3)
{
Fream();
textcolor(WHITE);
gotoxy(old_x-10,old_y);
cprintf("Sorry,you do not can");
gotoxy(old_x,old_y+2);
cprintf("Bye,Bye");
sleep(3);
exit(0);
}
break;
case Menu_y+2:
exit(0);
break;
default:
break;
}
break;
default:
break;
}
}while(key!=Esc);
}

[[italic] 本帖最后由 xianshizhe111 于 2008-1-16 17:53 编辑 [/italic]]
本帖最近评分记录
  • 岳C +2 我很赞同 2008-1-16 20:47
2008-01-16 09:49:30
sunkaidong

来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4493
专家分:141
注 册:2006-12-28
  得分:0 
我没有用tc用c++有错误.也不知道c++为什么提示错误,用tc试过了没有错误
----------------解决方案--------------------------------------------------------
提示: 作者被禁止或删除 内容自动屏蔽

坚持到底
2008-01-16 12:48:13
岳C

等 级:禁止发言
帖 子:354
专家分:0
注 册:2007-7-16
  得分:0 
提示: 作者被禁止或删除 内容自动屏蔽

坚持到底
2008-01-16 12:50:16
xianshizhe111

等 级:新手上路
帖 子:1451
专家分:0
注 册:2007-12-8
  得分:0 
第一个循环
这样改/*while((name1[k]=getch())!='\r')
        cprintf("%c",name1[k]);*/
----------------解决方案--------------------------------------------------------
  相关解决方案