Stopping the cursor from moving

This is a discussion on Stopping the cursor from moving within the C Programming forums, part of the General Programming Boards category; Is there anyway that I can stop the cursor from moving from a set point on my screen? Say I ...

  1. #1
    Registered User Inept Pig's Avatar
    Join Date
    Apr 2002
    Posts
    140

    Stopping the cursor from moving

    Is there anyway that I can stop the cursor from moving from a set point on my screen?

    Say I have this (very simple) code:

    Code:
    printf("Enter a number (0-9) ->");
    scanf("%d", &number);
    The cursor would start off after the arrow, but could be moved around before the number was entered (Say by pressing enter and such), I was wondering if there was a way in which I can STOP the user from moving the cursor, for any reason other than to input?

    And I'm aware I've been told about using scanf, but it's a simple example, and none to complex... bit like me

    Thanks for any advice
    Money frees you from doing things you dislike. Since I dislike doing nearly everything, money is handy - Groucho Marx

  2. #2
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Why don't you just scan for enter, and if it is pressed loop your input scanning? If you want to literally kill the cursor, I've only seen this for Windows:
    Code:
    #include <windows.h>
    
    void KillCursor ( void );
    
    void KillCursor ( void )
    {
    	CONSOLE_CURSOR_INFO cci;
    	cci.dwSize = 1;
    	cci.bVisible = FALSE;
    	SetConsoleCursorInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &cci );
    }
    The world is waiting. I must leave you now.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    To do what you ask requires non-standard functions, in order to read unbuffered keyboard input.

    If you have Windows, and the getch() function in conio.h, you could try something like this:
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <ctype.h>
    
    int main(void)
    {
    	int c, i = 0;
    	char buf[BUFSIZ];
    	
    	printf ("Your message >");
    	while ((c = getch()) != EOF && c != '\n' && c != '\r')
    	{
    		if (isalnum(c))
    		{
    			buf[i++] = c;  /* do some overflow checking!*/
    			putchar (c);
    		}
    	}
    	
    	buf[i] = '\0';
    	
    	printf ("\nbuf is >%s<\n", buf);
    	return (0);
    }
    This is only sample code to show you how to get started, to use it properly requires further changes to make it safe. But it is safe to compile and run, just don't overfill that buffer!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User Inept Pig's Avatar
    Join Date
    Apr 2002
    Posts
    140
    Thanks for your help, I can see how I meant to do it now

    Joy!
    Money frees you from doing things you dislike. Since I dislike doing nearly everything, money is handy - Groucho Marx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-23-2007, 11:05 PM
  2. moving median function
    By supermeew in forum C Programming
    Replies: 0
    Last Post: 05-04-2006, 02:37 PM
  3. 3D moving
    By bluehead in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2005, 04:46 AM
  4. Simple program i cant get (dot moving)
    By Lupusk9 in forum C++ Programming
    Replies: 4
    Last Post: 09-14-2004, 08:04 PM
  5. Stopping a window from moving
    By Mithoric in forum Windows Programming
    Replies: 2
    Last Post: 03-18-2004, 11:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21