一个不理解的错误,菜鸟级别,请教高手!
#include<stdio.h>#include<stdlib.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
void getstr(int x,int y,char *str)
{
int key;
char ch;
char s[2];
int i=0;
s[1]='\0';
setfillstyle(SOLID_FILL,WHITE);
setcolor(LIGHTGRAY);
outtextxy(x+i*8,y,"_");
while((key=getch())!=13)
{
if((key==8)||(key==75))
{
if(i>0)
{
i--;
bar(x+i*8,y,x+(i+2)*8-1,y+8);
outtextxy(x+i*8,y,"_");
}
}
else
if(ch=(char)(key&0x00ff)) //调试时,此处显示错误,但就是不白
{
str[i]=ch;
s[0]=ch;
bar(x+i*8,y,x+(i+1)*8-1,y+9);
setcolor(LIGHTGRAY);
outtextxy(x+i*8,y,s);
outtextxy(x+(i+1)*8,y,"_");
i++;
}
else
{
sound(1000);
delay(100);
nosound();
}
}
str[i]='\0';
setcolor(WHITE);
outtextxy(x+i*8,y,"_");
}
void main()
{
int gd=DETECT;
int gm;
char *str1;
initgrah(&gd,&gm," ");
setbkcolor(1);
getstr(100,100,str1);
getch();
closegraph();
}