• C

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................
nabeenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mayank SAssociate Director - Product EngineeringCommented:
In the graphics mode, it is not advisable to use clrscr (). Use cleardevice () instead.

Mayank.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.