Good day, i'm new in C.. can you give me some idea in how to program a moving cursor in the output screen and highlight the text... because i will use this in my coming final project in school.. we will make a system in TURBO C..

hoping for reply... THANK YOU!

In Turbo C you can use gotoxy(), and for the highlighting you'd probably use textcolor(). Read the documentation for further details about those two functions.


inb4 don't use Turbo C.

In Turbo C you can use gotoxy(), and for the highlighting you'd probably use textcolor(). Read the documentation for further details about those two functions.


inb4 don't use Turbo C.

Thank You for tha Information sir... but my problem that i can move/manipulate the cursor left, right, down, up in the output screen.

Hope you can help me...

but my problem that i can move/manipulate the cursor left, right, down, up in the output screen.

I don't understand.

Thank You for tha Information sir... but my problem that i can move/manipulate the cursor left, right, down, up in the output screen.

Hope you can help me...

He already told you how -- call gotoxy().

hope this help:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
long k;
clrscr();
for(i=0;i<=300;i++)
{
clrscr();
for(j=0;j<=i;j++)
{
printf(" ");
  }
//printf("abc");
for(k=1;k<=900000;k++);//increasing this value will slow down the cursor speed.
   }              
getch();
}

>>for(k=1;k<=900000;k++);//increasing this value will slow down the cursor speed.

Horrible waste of CPU time! That is dependent on CPU speed. In Turbo C call its delay() function.

Deciptikon, Ancient Dragon, and student learner... thank you for the reply. When i was surfing in the net i come with this site "http://ascii-table.com/ansi-escape-sequences.php".. this is what i mean.. can you teach me how to do that "ANSI escape" or give some sample program...

Thank You so much...

You *might* be able to use ANSI escape sequences by loading ANSI.SYS. But it's a really bad solution to the problem when Turbo C already supports such library functions as gotoxy() and textcolor().

#include<stdio.h>
#include<conio.h>

#define d1 gotoxy(1,1);textcolor(RED);cprintf(" P");textcolor(7);cprintf("relim       ");
#define d2 gotoxy(1,6);textcolor(RED);cprintf(" M");textcolor(7);cprintf("idterm      ");
#define d3 gotoxy(1,12);textcolor(RED);cprintf(" S");textcolor(7);cprintf("emi finals  ");
#define d4 gotoxy(1,18);textcolor(RED);cprintf(" F");textcolor(7);cprintf("inals       ");
#define keys gotoxy(1,24);printf("Esc = exit\tArrow keys = up/down/left/right");
#define d clrscr(); keys d1 d2 d3 d4

int c,cx=0,cy=0,i1,i2,i3,i4,i5,i6,i7; /*some variables will be use --in progress -*/ 
char c1,c2,c3,c4,c5,c6,c7,c8;
float f1,f2;

void updown()
  {
  switch(c)
    {
    case  72 : cy = cy - 1;
	       break;
    case  80 : cy = cy + 1;
	       break;
    default  : printf("");
    }
  }



void b2()
  {
  switch(cx)
    {
    case  1 : gotoxy(20,1);printf("PRELIM\n");
	      gotoxy(20,2);printf("PROGRAM 1\n");
	      gotoxy(20,3);printf("PROGRAM 2\n");
	      gotoxy(20,4);printf("PROGRAM 3\n");
	      break;
    case  2 : gotoxy(20,1);printf("MIDTERM\n");
	      gotoxy(20,2);printf("PROGRAM 1\n");
	      gotoxy(20,3);printf("PROGRAM 2\n");
	      gotoxy(20,4);printf("PROGRAM 3\n");
	      break;
    case  3 : gotoxy(20,1);printf("SEMI FINALS\n");
	      gotoxy(20,2);printf("PROGRAM 1\n");
	      gotoxy(20,3);printf("PROGRAM 2\n");
	      gotoxy(20,4);printf("PROGRAM 3\n");
	      break;
    case  4 : gotoxy(20,1);printf("FINALS\n");
	      gotoxy(20,2);printf("PROGRAM 1\n");
	      gotoxy(20,3);printf("PROGRAM 2\n");
	      gotoxy(20,4);printf("PROGRAM 3\n");
	      break;
    default : printf("");
    }
  }

void leftright()
  {
  if(c==77 || c==75)
    {
    if(c==77)

      if(cy==1)
      cx=1;
      else if(cy==2)
      cx=2;
      else if(cy==3)
      cx=3;
      else if(cy==4)
      cx=4;

    else if(c==75)
      cx=0;
    }
  else
    cx=0;
  }



void b1()
  {
  if(cy>=5)
    cy=1;
  else if(cy<=-1)
    cy=4;
  switch(cy)
    {
    case  1 : d textbackground(9); d1 textbackground(BLACK); d2 d3 d4
	      break;
    case  2 : d textbackground(9); d2 textbackground(BLACK); d3 d4
	      break;
    case  3 : d textbackground(9); d3 textbackground(BLACK); d4
	      break;
    case  4 : d textbackground(9); d4 textbackground(BLACK);
	      break;
    default : printf("");
    }
    leftright();
    b2();
  }





main()
  {
  d
  do
    {
    c = getch();
    d
    updown();
    b1();
    b2();
    }
  while(c!=0x1b);
  }

TESTING mo brad .. sensya na magulo yung gawa ko hehe 1st day ko plang ginawa e :))
this is our individual project for final
**note** my program is still in progress

to move cursor you need to ch=getch();
in loop;
then you have to just match ch=='P' or 'K','H','M'
left arrow = K
right arrow = M
up arrow = H
down arrow = P
now use gotoxy(x,y)
x++,y
x--,y
x,y++
x,y--

hi cutterpillow20 now I have the same problem as you had. could you get any awnser if yes then help me too. :) thanks

Didn't you read the rest of this thread???? No one can help you if you don't know how to read.

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.