954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

HELP! How to Move the cursor in turbo c

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!

cutterpillow20
Newbie Poster
9 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

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.

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

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...

cutterpillow20
Newbie Poster
9 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 
but my problem that i can move/manipulate the cursor left, right, down, up in the output screen.


I don't understand.

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 

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().

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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();
}
student_learner
Newbie Poster
12 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

>>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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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...

cutterpillow20
Newbie Poster
9 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

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().

deceptikon
Indubitably
Administrator
632 posts since Jan 2012
Reputation Points: 119
Solved Threads: 105
 
#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

zero9159743726
Newbie Poster
2 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You