How to Retrieve Cursor Value Using _conio_gettext Function?

  • Thread starter Thread starter vegetto34
  • Start date Start date
  • Tags Tags
    Functions
AI Thread Summary
The discussion revolves around using the _conio_gettext function to retrieve cursor values in a C program that involves user input and screen manipulation. The program prompts the user for a name, clears the screen, and allows the user to control a pencil character on a grid using the numeric keypad. The user expresses confusion about implementing the clrscr function and retrieving cursor values, specifically questioning the use of a buffer to store these values. Suggestions include using a do-while loop and clarifying the purpose of the _conio_gettext function prototype. The conversation highlights the need for better understanding of function usage and input handling in C programming.
vegetto34
Messages
16
Reaction score
0

Homework Statement



The program will request the user to enter a name. Once entered, the screen is cleared and it moves onto a new screen. If not, input is requested once again.

char name

Homework Equations



void clrscr()

Possibly if statements

printf ("Please enter your name:");
scanf( "%s", &name);


The Attempt at a Solution



#include <stdio.h>

int main()

void clrscr()

I don't really know how to use it. I've been trying to look around online for tutorials, but I don't see any good ones available. My lecture notes don't seem to help much either.

Thanks
 
Physics news on Phys.org
Your question is rather unclear. Are you asking what void functions in general are used for, or what, specifically, "void clscr()" is used for?
 
You call it. What's so hard about that? Given the name, the purpose of the function obviously is to clear the screen.
 
I got it to work. Seems to work. Just forgot to active l-conio in my compiler and how void functions work.

My problem right now is digit detection. Here is my problem statement:

Problem Statement:

Using the <conio.h> library, use simple text characters to animate a pencil which leaves a pencil
trace on the screen. The pencil will respond to player input; moving around the screen as
the player directs. If the player presses the ESC key or if the player gets a negative score,
the game stops.

The aim of the game is to join the numbers IN ORDER from 0 to 9, using the most direct
and efficient route.

Relevant Equations

I got the cursor working (void putchxy) working, by using a while loop. Under that, I used if statements to set it so that the direction is controlled by the numeric keypad.

Function prototype declared:
void putchxy (int x, int y, char pencil);


Working solution


#include <stdio.h>
#include <conio.h>

/*Function prototype: */
void putchxy (int x, int y, int pencil); /* Places pencil at coordinates (x,y) */
void clrscr(); /* Clears screen */
void cputsxy(int x, int y, char *s); /* */


/* Main */
int main()

{

char name;
char move;
char *s;
int score = 200;
int nextnumber;
int x = 40;
int y = 12;
int pencil = '+';


printf ("The object of the game is to the cursor +\naround the screen using the direction pad on the numeric keypad.\nJoin the digits in an ascending order to get a good score\nStart with 0\nPress ESC anytime to exit\n\n");
printf("Please enter your username.\n");
scanf("%s",&name);

/* Clears Screen after prompt */
clrscr();


/* Print out borders of the game */

printf("Score: %i Go to: %i Username: %c\n",score, nextnumber, name);
printf(" /-----------------------------------------------------------------------------\\");
printf(" | 5 |");
printf(" | |");
printf(" | |");
printf(" | 1 3 |");
printf(" | |");
printf(" | |");
printf(" | 8 |");
printf(" | 0 |");
printf(" | |");
printf(" | |");
printf(" | |");
printf(" | 7 6 |");
printf(" | |");
printf(" | |");
printf(" | 2 |");
printf(" | 4 |");
printf(" | |");
printf(" | |");
printf(" | |");
printf(" | 9 |");
printf(" | |");
printf(" | |");
printf(" | 7 |");
printf("\\-----------------------------------------------------------------------------/");


while ((int)move !=27)
{
putchxy(x, y, pencil);

move = getch();

if (move == '8' && y > 1 )
{
y--;
}
else if (move =='2' && y <24)
{
y++;
}
else if (move =='4' && x > 2)
{
x--;
}
else if (move =='6' && x < 79)
{
x++;
}



}



return 0;
}



From what I've read, I think I may have to use to retrieve the value the cursor is on. The function prototype I may be able to use is:

void _conio_gettext(int x, int y, int x, int y, char buffer[]);

I'm guessing a do while loop could be used. The value will have to be stored somewhere so a char buffer is going to be used. I think that char buffer[4] is equivalent to holding 1 character. I don't know what to do from here.

Does the buffer collect the values of the spaces as well as the numbers that I randomly entered around the grid? Is the function prototype I'm using appropriate or should something else be used?

Hope you guys can help.

Thanks.
 

Similar threads

Replies
3
Views
1K
Replies
4
Views
2K
Replies
9
Views
4K
Replies
2
Views
1K
Replies
3
Views
2K
Replies
1
Views
2K
Replies
8
Views
7K
Back
Top