A small Help

Check out the following code

1
2
settextstyle(2,0,5);
outtextxy(10,40,"Hello");


I want to input a text after giving a space with the same style .....
for example after input "HI" the output should be like this.....

Hello HI
plz help
The easiest way would be to format your complete output and then call outtextxy just the once.

1
2
3
4
5
6
char buffer[1024] = {0}; // zero the buffer
strcpy(buffer, "Hello");
strcat(buffer, " ");
strcat(buffer, "HI");
settextstyle(2,0,5);
outtextxy(10,40,buffer);


or

1
2
3
4
5
const char data[] = "HI";
char buffer[1024] = {0}; // zero the buffer
sprintf(buffer, "Hello %s", data);
settextstyle(2,0,5);
outtextxy(10,40,buffer);


You can work out how long a string is, but it's harder work. If you're using BGI, as your fragment suggests, then you'll need to use textwidth() to work out how long the first string is so you can calculate x,y for the second string.

Probably something like (I don't have Borland anymore, so this is from memory...)

1
2
3
4
settextstyle(2,0,5);
outtextxy(10,40,"Hello");
dx = textwidth("Hello "); // with the space
outtextxy(10 + dx,40,"HI");


Andy
Last edited on
but when my first code is compiled.....the output is given in a style....
i wanted to know how the input is set to the same style.....

I'm still a bit unclear about what you want to do.

Are you trying to read text in using cin?

Also, are you calling initgraph() somewhere in your program?

Andy
the real deal is .....we can use styles in output using settextstyle and outtextxy and i want the same same for input also.....which unfortunately I don't know
This person asked the same question:

How to get input using GRAPHICS?
http://itpian.com/Coding/17962-How-to-get-input-using-GRAPHICS.aspx

The answer was to use getch() to read the chars without them being automatically shown and then echoing them back with your own BGI o/p code.

Prob. not the kind of answer you were hoping for!!

Andy

PS It's been years since I used Borland C++ and BGI, so I've run out of inspiration...
Last edited on
Topic archived. No new replies allowed.