printing to the 25th row

This is a discussion on printing to the 25th row within the C Programming forums, part of the General Programming Boards category; In text mode the demisions are 25x80 or x:80 y:25, right? Then why is writing to the 25th row using ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    printing to the 25th row

    In text mode the demisions are 25x80 or x:80 y:25, right? Then why is writing to the 25th row using the code below causing it to scroll?

    Code:
    #include <stdio.h>
    #include <conio.h>
    void drawScore(void);
    void drawBorder(void);
    
    struct playerData {
    	int x,y,score;
    	int oldy;
    };
    
    struct playerData player1 = {3,10}, player2 = {78,10};
    main()
    {
    	drawScore();
    	drawBorder();
    	getch();
    }
    
    void drawScore(void)
    {
    	gotoxy(3,1);
    	printf("Player 1");
    	gotoxy(3,2);
    	printf("Score: %d", player1.score);
    	gotoxy(20,1);
    	printf("x: %d y: %d ", player1.x, player1.y);
    	gotoxy(71,1);
    	printf("Player 2");
    	gotoxy(71,2);
    	printf("Score: %d", player2.score);
    	gotoxy(40,1);
    	printf("x: %d y: %d ", player2.x, player2.y);
    }
    
    void drawBorder(void)
    {  int i;
    	gotoxy(1,3);
    	for(i = 0; i < 80;i++)
    		printf("=");
    	gotoxy(1,25);
    	for(i = 0; i < 80;i++)
    		printf("=");
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Because of the advancing cursor. Basicly it advances off of the last position and rolls the screen up a row.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Then is there a way to write to the 25th row without causing it to scroll?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Have fun, because there is no ANSI way to do the form of screen manipulation you need.

    This isn't to say there is no way to do it; I know you can, I've just never really bothered to look into it. (I've seen it done in tons of ASCII/ANSI based games.)

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    Hi!

    The problem, more specific, is that writing anything in the lower-right corner of the screen will cause the cursor to advance to the next line... Just don't write anything in column 80 of line 25...

    Long, long ago I used Borlands Turbo C... I seem to remember that there is a global variable which affects this behavior. I don't remember its name, and it may only affect cprintf. Anyhow, cprintf is faster and allows you to use colors! (it does not allow redirection, however, but your application is meant to be interactive, so no problem there.)

    [edit]
    just looked it up for you...
    Code:
    _wscroll=0; /* disables scrolling */
    _wscroll=1; /* (re)enables scrolling */
    still not sure whether this works for any i/o or only for the conio.h functions
    [/edit]

    Hope this helps...
    alex
    Last edited by alex; 06-26-2002 at 02:50 PM.

  6. #6
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    I'm using the Borland C++ 4.5 compiler and tried your suggestion and put "extern _wscroll=1' before main , but it didn't make any differences.

    Thanks for you help anyways.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Aren't you supposed to set _wscroll to 0 to stop scrolling?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Tetris
    By estoyperdida in forum C Programming
    Replies: 8
    Last Post: 01-30-2008, 01:02 PM
  2. reading pictures and array
    By sunoflight77 in forum C++ Programming
    Replies: 0
    Last Post: 05-09-2005, 04:16 PM
  3. Animation not working....
    By aquinn in forum C Programming
    Replies: 7
    Last Post: 02-19-2005, 05:37 AM
  4. libtiff: TIFFWriteRGBAImage()?
    By dug in forum Game Programming
    Replies: 1
    Last Post: 07-09-2003, 10:01 AM
  5. Is there a bug in this part of my algorithm for connect 4?
    By Nutshell in forum Game Programming
    Replies: 8
    Last Post: 04-28-2002, 02:58 AM

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