高人好:请我帮看看,下面的程序到底怎么回事,无错误啊!怎么一运行就出致命错误。
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<dos.h>
#define HEX 0 /*hexadecimal*/
#define DEC 1 /*decimal*/
#define OCT 2 /*octal*/
#define BIN 3 /*binary*/
int index=0,choice=0; /*external variable*/
int button,mousex,mousey;
void set_screen(void);
void init_mouse(void);
void show_mouse(void);
void comment(void);
void display(int x,int y,char text[50]);
void process_program(void);
unsigned long convert_to_decimal(char *_num,int radix);
void get_mouse(void);
int getnum(char character);
int main(void)
{
clrscr(); /*clear screen*/
set_screen(); /*set screen CYAN*/
init_mouse();
show_mouse();
process_program();
getch();
return 0;
}
void set_screen(void)
{
textbackground(CYAN);
clrscr();
}
void init_mouse(void)
{
_AX=0;
geninterrupt(0x33);
}
void show_mouse(void)
{
_AX=1;
geninterrupt(0x33);
}
void comment(void)
{
textcolor(0); /*set text BLACK*/
display(10,5,"Hexadecimal:-"); /*output*/
display(10,7,"Decimal:-");
display(10,9,"Octal:-");
display(10,11,"Binary:-");
textbackground(LIGHTBLUE); /*set backcolor*/
display(23,5," ");
display(23,7," ");
display(23,9," ");
display(23,11," ");
if(choice==HEX) /*mouse position*/
gotoxy(24,5);
else if(choice==DEC)
gotoxy(24,7);
else if(choice==OCT)
gotoxy(24,9);
else if(choice==BIN)
gotoxy(24,11);
}
void display(int x,int y,char text[50])
{
gotoxy(x,y);
cprintf(text);
}
void process_program(void)
{
char ch,string[80]={"\0"},buffer[80];
int x,y;
unsigned long deci;
comment();
while(1)
{
if(kbhit())
{
ch=getch();
if(ch==27) /*input ESC exit program*/
break;
if(ch=='\b' && wherex()>=24) /*input is '\b'*/
{
cprintf("\b"); /*delete current input '\b'*/
cprintf("%c",255);
cprintf("\b"); /*delete privious character*/
if(index!=0)
index--; /*array_length -1*/
string[index]=NULL;
}
else if(wherex()>=24 && ch>='0' && ch<='f') /*input is not '\b'*/
{
cprintf("%c",ch);
string[index]=ch;
string[index+1]=NULL;
index++;
}
x=wherex(),y=wherey();
switch(choice)
{
case HEX:
deci=convert_to_decimal(string,16);
gotoxy(24,7);
printf("%ld ",deci);
gotoxy(24,9);
printf("%s ",ltoa(deci,buffer,8));
gotoxy(24,11);
printf("%s ",ltoa(deci,buffer,2));
break;
case DEC:
deci=atol(string);
gotoxy(24,5);
printf("%s ",ltoa(deci,buffer,16));
gotoxy(24,9);
printf("%s ",ltoa(deci,buffer,8));
gotoxy(24,11);
printf("%s ",ltoa(deci,buffer,2));
break;
case OCT:
deci=convert_to_decimal(string,8);
gotoxy(24,5);
printf("%s ",ltoa(deci,buffer,16));
gotoxy(24,7);
printf("%ld ",deci);
gotoxy(24,11);
printf("%s ",ltoa(deci,buffer,8));
case BIN:
deci=convert_to_decimal(string,2);
gotoxy(24,5);
printf("%s ",ltoa(deci,buffer,16));
gotoxy(24,7);
printf("%ld ",deci);
gotoxy(24,9);
printf("%s ",ltoa(deci,buffer,8));
} /*switch*/
gotoxy(x,y);
} /*if*/
get_mouse();
mousex++,mousey++; /*attentio*/
if(mousex/8>23 && mousex/8<50 &&mousey/16==2 && button&1==1)
{
choice=HEX;
process_program();
}
else if(mousex/8>23 && mousex/8<50 && mousey/16==3 && button&1==1)
{
choice=DEC;
process_program();
}
else if(mousex/8>23 && mousex/8<50 && mousey/16==4 && button&1==1)
{
choice=OCT;
process_program();
}
else if(mousex/8>23 && mousex/8<50 && mousey/16==5 && button&1==1)
{
choice=BIN;
process_program();
}
}
}
unsigned long convert_to_decimal(char *_num,int radix)
{
int i,len;
unsigned long deci=0;
len=strlen(_num);
len--;
for(i=0;i!=_num[i];i++)
{
deci+=(getnum(_num[i])*pow(radix,len));
len--;
}
return deci;
}
int getnum(char character)
{
char string[36]={"0123456789abcdefghijklmnopqrstuvwxyz"};
int i;
for(i=0;i<=35;i++)
{
if(string[i]==character)
break;
}
return i;
}
void get_mouse(void)
{
_AX=3;
_BX=0;
geninterrupt(0x33);
button=_BL;
mousex=_CX;
mousey=_DX;
}
这个程序是将16,10,8,2进制之间的转换。
----------------解决方案--------------------------------------------------------
晕~~这么长,printf 控制下格式多好~~
----------------解决方案--------------------------------------------------------
首先XP中是不能这样调用鼠标的
其次,这个程序缺少重要的注释,需要花很大精力去看,看完自己都能写出一个来了,不值得。
----------------解决方案--------------------------------------------------------
我用TC2.0也注解不了汉字啊
----------------解决方案--------------------------------------------------------
/*………………汉字………………*/
----------------解决方案--------------------------------------------------------
win-tc 1.9.1
----------------解决方案--------------------------------------------------------
这吗长,这个用的着这吗长吗?
----------------解决方案--------------------------------------------------------
我们是来学习的,不是和你来做口舌之争来了,understand?
----------------解决方案--------------------------------------------------------
我希望你可以用c++的程序重新编写一遍这样利于大家看那里不是有汉字库么?
也许能给你提出经典的建议
这么大的程序看起来很费劲的
----------------解决方案--------------------------------------------------------
哎 太长拉 写程序要加注释的不支持汉语可以加english?
----------------解决方案--------------------------------------------------------