?
Solved

screen change color

Posted on 2003-03-30
15
Medium Priority
?
484 Views
Last Modified: 2012-08-14
#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
Comment
Question by:nabeen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 30

Accepted Solution

by:
Mayank S earned 750 total points
ID: 8236941
In the graphics mode, it is not advisable to use clrscr (). Use cleardevice () instead.

Mayank.
0
 

Expert Comment

by:Getch
ID: 8239236
#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
 
LVL 3

Expert Comment

by:r_a_j_e_s_h
ID: 8243412
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:deejay_45
ID: 8267844
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 8267861
Try using _clrscr () ; instead of clrscr () ; and see if it works (include <conio.h>, of course).
0
 

Expert Comment

by:deejay_45
ID: 8268370
_clrscr(); also does not work...
any other suggestions??
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8268418
>> 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
 

Expert Comment

by:deejay_45
ID: 8268438
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 8268443
The error must be that the function clrscr () is not defined/ declared or that it needs a prototype.
0
 

Expert Comment

by:deejay_45
ID: 8268449
is it possible for u to post a working solution for this problem??
because i do not get what u mean!
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8268458
What is the error?
0
 

Expert Comment

by:deejay_45
ID: 8268473
just a compiling error...says that clrscr () is not declared
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8268496
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
 
LVL 30

Expert Comment

by:Mayank S
ID: 8268501
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
 

Author Comment

by:nabeen
ID: 8354097
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question