XY position in C, repositioning

0

Personal I need the current "cursor" coordinates of the screen, so that the user stays in the current line.

EXAMPLE

void main{

    char nome[50];
    char sobrenome[50];

    int linhaAtual;
    linhaAtual = ????;

    gotoxy(1, linhaAtual);
    printf("Insira seu nome:");
    scanf("%[^\n]s", nome);

    gotoxy(1, linhaAtual);
    printf("Insira seu sobrenome:");
    scanf("%[^\n]s", nome);

    system("pause");
}

OBS

In the example I'm not taking into consideration the need to clean every line. I will develop.

RESEARCH

property wherex() , wherey() - does not work, I do not know why. property __LINE__ - apparently the count is different.

    
asked by anonymous 26.11.2014 / 23:45

1 answer

1

You are referring to the header conio.h (created for command line apps in Windows). This header is not part of the standard C language library, and there are very few compilers that support it natively.

What happens is that when running your application on IDEs like Qt Creator , or others that have a console of their own, there is no guarantee that these functions will work. It is best to use a compiler that natively supports conio.h , and then run your application directly from Windows ( cmd.exe ).

Well, to say that something "does not work" is quite vague, so I'm going to assume you had no problems compiling or linking to this library.

If you followed the guidelines above, according to the documentation, invoke the functions below:

int x = wherex();
int y = wherey();
printf("x: %d  y:%d\n", x, y);

will print the position (X, Y) of the cursor on the screen.

    
27.11.2014 / 00:40