Jump to content


Photo

C Cursor Positon


  • Please log in to reply
1 reply to this topic

#1 jakevfr

jakevfr

    Young Padawan

  • Members
  • Pip
  • 40 posts

Posted 27 February 2007 - 06:45 PM

How do I set the cursor position in C?

I've tried doing:
#include <windows.h> 

void gotoxy ( short x, short y )
{
  COORD coord = {x, y};
  SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
}

int main()
{
	gotoxy(5,5);
	system("cls");
	printf("Hello World!");
}
but my compiler (Digital Mars) give me:

COORD coord = {x, y};
^
file.c(5) : Error: constant initializer expected
--- errorlevel 1


It's been a while since I've coded in C so I have no idea what that means :worthy:

#2 Ali Imran

Ali Imran

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 19 July 2007 - 01:57 PM

I tested it with mingw-gcc and it works just fine.

secondly calling system("cls"); will result in caret going back to top-left corner of screen.

libraries dispatched with DMC are way too old and have not been updated since ages, I noticed this when I was porting my windows library. So I suggest you go and download dev c++ from http://www.bloodshed.net which comes alongwith backend mingw-gcc compiler, and is very good the produce statically linked executables.


regards

Edited by Ali Imran, 19 July 2007 - 02:03 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users