3
#include <stdio.h>
#include <dos.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
#define MAX 25

main(){
    int a[MAX],i,j,lvl=2,score=0;
    float time=1.0,speed;
    speed=time/lvl;

    clrscr();

    for(i=0;i<MAX;i++)
        a[i]=rand()%50+1;

    while(1){
        for(j=0;j<MAX;j++){
            gotoxy(a[j],1);
            printf("*");
            gotoxy(1,1);
            insline();
            sleep(speed);
            score++;
            gotoxy(57,1);
            clrscr();
            printf("%d",score);
            if(score==100)
                lvl++;
        }
    }
}

Hi i'm trying to print the score on the upper right corner of the screen using gotoxy(). I used gotoxy(1,1) to set the cursor position where blank line should be inserted using insline(). but everytime I printed the score on the screen, it's printing the score continous as shown below:

DOS screenshot with scores repeating down the right side

emphasized texts there other way to print the score and delete it on its last position when insline() inserts a new line so that the last score will not be printed on the screen but the current score only?

Sumit Singh
  • 15,743
  • 6
  • 59
  • 89
third_
  • 67
  • 1
  • 2
  • 6

1 Answers1

2

You should use this function

WriteConsoleOutput(....);

Check it on MSDN

http://msdn.microsoft.com/en-us/library/windows/desktop/ms687404(v=vs.85).aspx

Mahmoud Fayez
  • 3,398
  • 2
  • 19
  • 36