Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gotoxy function with C ( linux/unix )

Tags:

c

linux

I am making a terminal software like GNU MC and I need gotoxy foo, but it has to be in C. It can be in macro or in C, but not in ASM code because I don`t know ASM. Any bit operators can be used too, but I had no idea how to pseudocode it or how to start doing this. Any advice will be most appreciated :)

like image 742
Ilian Zapryanov Avatar asked Dec 03 '22 01:12

Ilian Zapryanov


2 Answers

Hope this snippet works with you.

I found these snippet on google long ago. I just saved it on my disk, now after seeing your post I just opened it.

Code

#include <stdio.h>
#include <stdlib.h>

void gotoxy(int x,int y)
{
    printf("%c[%d;%df",0x1B,y,x);
}

int main(void)
{
    gotoxy(10,10);
    printf("hello world");
    return 0;
} 
like image 176
niko Avatar answered Dec 14 '22 20:12

niko


Is this function sufficient?

void gotoxy(int x, int y)
{
    printf("You are now at position (%d, %d). You"\
           " look around and you see a vast emptiness...", x, y);
}

You do, however, mention that you are using software like GNU MC (Midnight Commander?), so perhaps you actually mean something more like:

void goto_url(char* url) { ... code here... }
like image 36
Arafangion Avatar answered Dec 14 '22 22:12

Arafangion