C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
change output colour Posted by binnykt on 29 Sept 2008 at 10:16 AM
the outpt screen in turbo c++ console is a black background with white characters,i want to to change that but i have no idea.please suggest a
remedy?
Report
Re: change output colour Posted by Jester_Racer on 30 Sept 2008 at 1:24 AM
: the outpt screen in turbo c++ console is a black background with
: white characters,i want to to change that but i have no idea.please
: suggest a
: remedy?
:

Do you know Google???
Anyway, you can use the ncurses library.
Report
Re: change output colour Posted by AsmGuru62 on 30 Sept 2008 at 2:31 AM
: : the outpt screen in turbo c++ console is a black background with
: : white characters,i want to to change that but i have no idea.please
: : suggest a
: : remedy?
: :
:
: Do you know Google???
: Anyway, you can use the ncurses library.
:
Try that code:
#include <conio.h>

int main ()
{
	textcolor (WHITE);
	cprintf ("\n-- WHITE COLOR!");

	textcolor (YELLOW);
	cprintf ("\n-- YELLOW COLOR!");

	return 0;
}
Report
Re: change output colour Posted by binnykt on 30 Sept 2008 at 3:33 AM
: : : the outpt screen in turbo c++ console is a black background with
: : : white characters,i want to to change that but i have no idea.please
: : : suggest a
: : : remedy?
: : :
: :
: : Do you know Google???
: : Anyway, you can use the ncurses library.
: :
: Try that code:
:
: 
: #include <conio.h>
: 
: int main ()
: {
: 	textcolor (WHITE);
: 	cprintf ("\n-- WHITE COLOR!");
: 
: 	textcolor (YELLOW);
: 	cprintf ("\n-- YELLOW COLOR!");
: 
: 	return 0;
: }
: 
:

Thanks,well it did change the text colour but I also want to change the
background color from black to say blue.
Report
Re: change output colour Posted by binnykt on 1 Oct 2008 at 8:07 PM
: : : : the outpt screen in turbo c++ console is a black background with
: : : : white characters,i want to to change that but i have no idea.please
: : : : suggest a
: : : : remedy?
: : : :
: : :
: : : Do you know Google???
: : : Anyway, you can use the ncurses library.
: : :
: : Try that code:
: :
: : 
: : #include <conio.h>
: : 
: : int main ()
: : {
: : 	textcolor (WHITE);
: : 	cprintf ("\n-- WHITE COLOR!");
: : 
: : 	textcolor (YELLOW);
: : 	cprintf ("\n-- YELLOW COLOR!");
: : 
: : 	return 0;
: : }
: : 
: :
:
: Thanks,well it did change the text colour but I also want to change
: the
: background color from black to say blue.
:
Well i did get a program to do just that check it out


// This will change the background
#include<windows.h>
#include<conio.h>
#include<stdio.h>
const int NotUsed = system( "color 1b" );
int main()
{
printf("Hallo");
getch();
return 0;
}

Report
Re: change output colour Posted by MT2002 on 1 Oct 2008 at 8:31 PM
Dont initialize globals like that. All that is needed is this:

#include<windows.h>
#include<conio.h>
#include<stdio.h>

int main()  
{  
  system ("color 1b");
  printf("Hallo");
  getch(); 
  return 0;  
}

Take note that this is both compiler dependent (Not all compiliers support conio.h and windows.h) and non portable (Will not work on other operating systems but Windows)


Report
Re: change output colour Posted by Lundin on 1 Oct 2008 at 11:38 PM
system() is found in stdlib.h, you don't need to use non-standard headers at all. This code works on every C compiler in the world:

#include <stdio.h>
#include <stdlib.h>

int main()
{
  #ifdef _WIN32
    system("color 1b");
  #endif

  printf("Hello");

  getchar();
  return 0;
}

Report
Re: change output colour Posted by binnykt on 4 Oct 2008 at 6:51 AM
: system() is found in stdlib.h, you don't need to use non-standard
: headers at all. This code works on every C compiler in the world:
:
:
: #include <stdio.h>
: #include <stdlib.h>
: 
: int main()
: {
:   #ifdef _WIN32
:     system("color 1b");
:   #endif
: 
:   printf("Hello");
: 
:   getchar();
:   return 0;
: }
:
:
Thanks Lundin.Your program worked as well.It shows that there are many ways to write a program in the same language to get the same result.
Report
Re: change output colour Posted by MT2002 on 4 Oct 2008 at 8:19 AM
: : This code works on every C compiler in the world:

Just a slight nitpick...

That code may not work on all compiliers in the world. In a freestanding envirement, <stdio.h> isnt required by the standard to be implemented do to memory restrictions. (17.4.1.3 of the C++ standard) I learned this the hard way when learning GBA programming as the compiler didnt support <stdio.h> nor <iostream>

This doesnt apply to most hosted compiliers though but just wanted to mention it.

You are right that there is no need for non standard headers here though. Thanks for fixing it


Report
Re: change output colour Posted by binnykt on 4 Oct 2008 at 6:46 AM
: Dont initialize globals like that. All that is needed is this:
:
:
: #include<windows.h>
: #include<conio.h>
: #include<stdio.h>
: 
: int main()  
: {  
:   system ("color 1b");
:   printf("Hallo");
:   getch(); 
:   return 0;  
: }
:
: Take note that this is both compiler dependent (Not all compiliers
: support conio.h and windows.h) and non portable (Will not work on
: other operating systems but Windows)
:
:
: Thanks & yes it did work!its more simple than the other one

Report
Re: change output colour Posted by AsmGuru62 on 5 Oct 2008 at 4:26 AM
: : : Try that code:
: : :
: : : 
: : : #include <conio.h>
: : : 
: : : int main ()
: : : {
: : : 	textcolor (WHITE);
: : : 	textbackground (RED);
: : : 	cprintf ("\n-- WHITE COLOR!");
: : : 
: : : 	textcolor (YELLOW);
: : : 	cprintf ("\n-- YELLOW COLOR!");
: : : 
: : : 	return 0;
: : : }
: : : 
: : :
: :
: : Thanks,well it did change the text colour but I also want to change
: : the
: : background color from black to say blue.
: :

See RED. Logically speaking the CONIO.H file should contain the other functions to manipulate the CONsole I/O and simple opening that file and looking for "textcolor" will give you "textbackground" too.
Report
Re: change output colour Posted by binnykt on 5 Oct 2008 at 8:25 PM
: : : : Try that code:
: : : :
: : : : 
: : : : #include <conio.h>
: : : : 
: : : : int main ()
: : : : {
: : : : 	textcolor (WHITE);
: : : : 	textbackground (RED);
: : : : 	cprintf ("\n-- WHITE COLOR!");
: : : : 
: : : : 	textcolor (YELLOW);
: : : : 	cprintf ("\n-- YELLOW COLOR!");
: : : : 
: : : : 	return 0;
: : : : }
: : : : 
: : : :
: : :
: : : Thanks,well it did change the text colour but I also want to change
: : : the
: : : background color from black to say blue.
: : :
:
: See RED. Logically speaking the CONIO.H file should contain the
: other functions to manipulate the CONsole I/O and simple opening
: that file and looking for "textcolor" will give you "textbackground"
: too.
:


Yes i know it changes The text background But i want t o change the
colour of the whole console
Thanks






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.