Help - Search - Members - Calendar
Full Version: C Cursor Positon
Pixel2Life Forum > Help Section > Desktop Programming
jakevfr
How do I set the cursor position in C?

I've tried doing:
CODE
#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:
QUOTE
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 sad.gif
Ali Imran
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
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.