How to Retrieve Cursor Value Using _conio_gettext Function?

  • Thread starter vegetto34
  • Start date
  • Tags
    Functions
In summary, the conversation discusses a program that requests user input for a name and then clears the screen and moves onto a new screen. It also mentions the use of void functions, if statements, and the <conio.h> library for digit detection and animation. The goal of the program is to join numbers in ascending order while avoiding negative scores or pressing the ESC key to exit the game. The conversation also includes a relevant equation and a suggested function prototype for retrieving the value the cursor is on. The conversation ends with a request for help on using the function prototype and clarifying the use of a char buffer.
  • #1
vegetto34
16
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
  • #2
Your question is rather unclear. Are you asking what void functions in general are used for, or what, specifically, "void clscr()" is used for?
 
  • #3
You call it. What's so hard about that? Given the name, the purpose of the function obviously is to clear the screen.
 
  • #4
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.
 

1. What is a void function?

A void function is a type of function in programming that does not return any value. It is used to perform a specific task or operation without needing to return a result.

2. How do I declare a void function?

To declare a void function, you must use the keyword "void" in the function header followed by the name of the function and a set of parentheses. For example: void myFunction();

3. Can a void function have parameters?

Yes, a void function can have parameters. These parameters are used to pass values into the function and can be used within the function to perform operations. However, since void functions do not return a value, the parameters must be passed by reference.

4. How do I call a void function?

To call a void function, you simply need to use the function name followed by a set of parentheses. If the function has parameters, you will need to provide the necessary arguments within the parentheses. For example: myFunction();

5. What are the benefits of using void functions?

Void functions are useful for breaking down a complex task into smaller, more manageable parts. They also help to improve code readability and organization. Additionally, void functions can be called multiple times within a program, making them efficient for repetitive tasks.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
893
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
17
Views
2K
  • Programming and Computer Science
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
Back
Top