Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 490
  • Last Modified:

screen change color

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main()
{
  int p=DETECT,q;
  initgraph(&p,&q,"");
  clrscr();
  setbkcolor(BLACK);
  printf("THIS IS A TEST PROGRAM");
  getch();
}

In the following program has got no error and I understand every function I used above.
But whenever I use initgraph function and then clrscr() function I get 75% of my screen in any other color usually gray
and 25% is always black. I cannot correct it even if I use setbkcolor() after each clrscr() command.
I could not figure out what is wrong and which function is making problem.
PLEASE HELP................
0
nabeen
Asked:
nabeen
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
In the graphics mode, it is not advisable to use clrscr (). Use cleardevice () instead.

Mayank.
0
 
GetchCommented:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#define RETURN_EXIT_SUCCESS 0

int main()
{
    int driver,mode;
    detectgraph(&driver,&mode);
    initgraph(&driver,&mode,"C:\\BC45\\BGI"); // define here the path of the bgi graphics driver
    cleardevice();
    setbkcolor(BLACK);
    printf("%s","THIS IS WAT YOU NEED. \n");
    getch();
    return RETURN_EXIT_SUCCESS;
}
0
 
r_a_j_e_s_hCommented:
hi nabeen
            u should use cleardevice() command to clear the screen in graphics mode. clrscr() is for text mode only.



#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main()
{
 int p=DETECT,q;
 initgraph(&p,&q,"");
//-----------------------------------
 clrscr();// for text mode
 cleardevice();//for graphics mode
//---------------------------
 setbkcolor(BLACK);
 printf("THIS IS A TEST PROGRAM");
 getch();
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
deejay_45Commented:
I've tried using the clrscr(); but it shows an error while compiling in Microsoft Visual C++ 6.0 . What libraries do i need to initialise in order to use the function?? How do i go about it using MS VC++ 6.0 as my compiler?

Just out of curiosity!
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Try using _clrscr () ; instead of clrscr () ; and see if it works (include <conio.h>, of course).
0
 
deejay_45Commented:
_clrscr(); also does not work...
any other suggestions??
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> using MS VC++ 6.0 as my compiler

clrscr () is screen-based, and VC++ is window-based. clrscr () is supposed to clear the "screen". I guess VC++ starts the execution of your program in a cleared command window anyway (I've not worked much on VC++ - I'm more into Java.... that's why I don't have VC++ on my system too. I just have an old Turbo C++ compiler, which I'd used once while working with micro-controllers).

Mayank.
0
 
deejay_45Commented:
no..there is an ERROR while compiling...
that's what i mean by not working....
and even though MS VC++ is windows based, the programs created are run in DOS
0
 
Mayank SAssociate Director - Product EngineeringCommented:
The error must be that the function clrscr () is not defined/ declared or that it needs a prototype.
0
 
deejay_45Commented:
is it possible for u to post a working solution for this problem??
because i do not get what u mean!
0
 
Mayank SAssociate Director - Product EngineeringCommented:
What is the error?
0
 
deejay_45Commented:
just a compiling error...says that clrscr () is not declared
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Yeah! Like I said:

>> The error must be that the function clrscr () is not defined/ declared or that it needs a prototype.

Sorry, deejay, don't know how to help you with that on VC.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Yeah! Like I said:

>> The error must be that the function clrscr () is not defined/ declared or that it needs a prototype.

Sorry, deejay, don't know how to help you with that on VC.
0
 
nabeenAuthor Commented:
i want tsr of this function. can any one provide?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now