1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: How to use void functions

  1. Sep 21, 2009 #1
    1. The problem statement, all variables and given/known data

    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

    2. Relevant equations

    void clrscr()

    Possibly if statements

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

    3. 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.

  2. jcsd
  3. Sep 22, 2009 #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?
  4. Sep 22, 2009 #3

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    You call it. What's so hard about that? Given the name, the purpose of the function obviously is to clear the screen.
  5. Sep 22, 2009 #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");

    /* Clears Screen after prompt */

    /* 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 |");

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

    move = getch();

    if (move == '8' && y > 1 )
    else if (move =='2' && y <24)
    else if (move =='4' && x > 2)
    else if (move =='6' && x < 79)


    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.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook