How to Retrieve Cursor Value Using _conio_gettext Function?

  • Thread starter Thread starter vegetto34
  • Start date Start date
  • Tags Tags
    Functions
Click For Summary

Discussion Overview

The discussion revolves around the use of the _conio_gettext function in a C programming context, specifically for retrieving the cursor value on the screen during a game implemented using the library. Participants explore the functionality of various functions, including clrscr and putchxy, and discuss the implementation of user input handling and game mechanics.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant describes a program that prompts the user for a name, clears the screen, and then presents a game involving cursor movement and score tracking.
  • Another participant questions the clarity of the initial question, asking whether it pertains to void functions in general or specifically to clrscr.
  • A different participant asserts that the purpose of clrscr is to clear the screen, suggesting that the function's name indicates its functionality.
  • One participant shares a working solution for a game that involves moving a pencil character around the screen using the numeric keypad, mentioning the use of a while loop and if statements for direction control.
  • The same participant expresses uncertainty about using _conio_gettext, questioning whether the buffer collects values from the grid and if the function prototype is appropriate for their needs.
  • They also mention the potential use of a do-while loop for their implementation.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the clarity of the original question or the specific use of the _conio_gettext function. There are multiple viewpoints regarding the understanding and application of the functions discussed, indicating that the discussion remains unresolved.

Contextual Notes

Some limitations include the unclear definition of the problem statement and the specific requirements for using the _conio_gettext function. There are also unresolved questions about the functionality of the buffer in relation to the grid values.

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 ·
Replies
3
Views
2K
Replies
9
Views
2K
Replies
17
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
7K