开发者

Implementing backspace using outtextxy in graphics.h in c

I was trying to create a text e开发者_StackOverflowditor in c. but i am facing a problem with the backspace character. and when i am trying to print this with outtextxy a strange character is appearing. i tried following code for this backspace:

str[2]="\b ";

outtextxy(x,y,str);

This is working fine under textmode but not working under graphics mode.


That's been a good 20 years since I last laid eyes on that. It is a low-level graphics output function in BGI (IIRC). You'll get the glyph for code 8, a rectangle with a circle in the OEM character set.

To make it act like, say, puts(), you'll have to interpret the control codes yourself. If you see a backspace (char 8), you'll have to update your internal "cursor position" variable and move x back by the font width. Same for '\n' (increment y) and '\r' (set x to 0).


Since U are in Graphics mode:

  1. [STEP 1] Keep track of current position using two ints (say x,y)

  2. [STEP 2] Whenever backspace is pressed:

    1st Check if x==0,y==0 : Emit a beep;

    Else check if x==0, y>0 : Then make x= screen-width, y=y-1;

    Else check if x>0, y>0 : Then x=x-1;

Now That U hav the right x,y co-ordinates, just outtextxy a NULL/space character at the position.

NOTE: After outtextxy do NOT increment x as the cursor is still supposed to be at the prev character position.

GOOD LUCK!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜