hello sir,
actually what i want to do is to print a series of characters using outtextxy() function in c++ graphics.
say my array contains '1','2','3','4','5'.
using a for loop i want to print them at diff positions on screen.

char c[]={'1','2','3','4','5'}
int i,j=100

for(i=0;i<5;i++)
{
outtextxy(100,j,c);
j+=100;
}

but this prints all the characters at all the places.
like

12345

12345

12345

12345

12345

12345

but what i want is
1

2

3

4

5.

please help me out .

Thanks

Recommended Answers

All 9 Replies

You forgot to add the index of the string you wish to print...

outtextxy(100,j,c[i]);

so its printing the entire string each time. Tell me if that works.

Thank you for giving me your time..
I tried what you said but that does not work..

What compiler are you using? Another post on Daniweb states that that fuction is Borlan specific.

Also are you required to use this function, because there is easier ways to implement this.

What compiler are you using? Another post on Daniweb states that that fuction is Borlan specific.

Also are you required to use this function, because there is easier ways to implement this.

I am using turbo C.
Could you please suggest me any other way of doin it..

Can you simply insert endl's in your nested loop? What is your overall objective? You could implement that function yourself pretty easily in my opinion. If you are still struggling I will help this evening with code.

I was messing around with something that might interest you in experimenting with.

#define _WIN32_WINNT 0x0500

#include "stdafx.h"
#include <Windows.h>


int _tmain(int argc, _TCHAR* argv[])
{
  HWND console = GetConsoleWindow();
  RECT r;
  GetWindowRect(console, &r); //stores the console's current dimensions

  //MoveWindow(window_handle, x, y, width, height, redraw_window);
  MoveWindow(console, r.left, r.top, 800, 600, TRUE);
  while(1){
	    GetWindowRect(console, &r); //stores the console's current dimensions
		printf("Left:%d  Right:%d  Top:%d  Bottom:%d\n",r.left,r.right,r.top,r.bottom);
		 Sleep(5000);
  
  }
  //unreachable code!!!
  system("pause");
  return 0;
}

This function basically grabs the x values for the left and right side of the console window, and the y values for the top and bottom of the window and prints them to the console window every 5 seconds.

What you might consider doing is writing a new outtextxy() that uses these properties. You would just have to calculate the window with by (r.right - r.left) and height by (r.bottom - r.top). This wont get you too far considering that font size will matter because those measurements are done in pixels...

You might just considering looping some newlines in their since that will be easy and give you the output you require. Just something fun to play around with.

first google result for "outtextxy" says:

void outtextxy(int x, int y, char *textstring);

Note the "*" character, indicating that it expects a C-style string (or Null-character-terminated array of characters) for the text to display, not a single character. Replace your first line above with:

const char* strings[] = {"1", "2", "3", "4", "5"};

Note the double-quotes instead of single-quotes around each value! (and index into the array as Satyrn suggested...)

first google result for "outtextxy" says:

void outtextxy(int x, int y, char *textstring);

Note the "*" character, indicating that it expects a C-style string (or Null-character-terminated array of characters) for the text to display, not a single character. Replace your first line above with:

const char* strings[] = {"1", "2", "3", "4", "5"};

Note the double-quotes instead of single-quotes around each value! (and index into the array as Satyrn suggested...)

Thanks a lot......
It worked

Happy to help. Don't forget to mark the thread as "solved"! Or post back if you have more questions on the same program. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.