XY position in C, repositioning

Asked

Viewed 2,130 times

0

I am in need of the current "cursor" coordinates of the screen, for the user to remain 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 am not taking into consideration the need to clean up every line. I will develop.

RESEARCH

property wherex() , wherey() - It doesn’t work, I don’t know why. property __LINE__ - apparently the count is different.

  • I’m glad that __LINE__ didn’t work. Have you ever wondered why there is only the row and not the column in it? Let’s go to what is related to what you want: because the where?() does not work? If you who made the application do not know the reason, we know less yet. You did not put the #include you are using. This is important. I hope you are not using conio.h, this is not part of the standard and is obsolete.

  • @Guilherme-lautert for you, pointer = cursor? Edit the question and adjust that detail, it makes quite a difference.

  • @Bigown, I was curious about "I’m glad __LINE__ did not work out." and searched for this: http://www.lemoda.net/c/line-file-func/ Very interesting, in my previous search __LINE__, was pointed to as position of coordinate y, only no "file" was mentioned. #include conio.h, in fact is exactly what I am using, I am aware of the existence of the conio2.h, yet I thought there might be some parental property in C itself.

  • @karlphillip I know that pointer != cursor, but technically I don’t either | line as a cursor. Could not express me correctly at the time.

  • @Guilhermelautert I understand you, but when we want help from the community we have to use the technical terms that are part of the terminology of the area, otherwise we run the risk of not being understood. If cursor is an appropriate name or not to define this functionality I do not know, but the books, manuals and documentations refer to it by this name.

1 answer

1


Are you referring to the functions of header conio.h (created for command line apps on Windows). This header is not part of the standard C language library, and few compilers support it natively.

What happens is that when you run your application on Ides like Qt Creator, or others with their own console, 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 app directly from Command Prompt windows (cmd.exe).

Well, saying something "doesn’t work" is pretty vague, so I’ll assume you didn’t have any compilation or link problems with that library.

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

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

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

  • I believe my IDE has the conio.h, but it does not run correctly as you commented, because I own the #include conio.h and these commands have error when used.

  • Now we come to the point: what is the error? Be very specific, please, otherwise we can’t help you.

  • So what happens when you print x and y on screen? What are their values?

  • as I mentioned in the comment for @bigown, I had to use the library conio2.h, for my current conio.h does not have these functions, so when I try to compile it displays where?() not declared in this scope.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.