943,945 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 14215
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Oct 26th, 2004
0

How to code a program that can show color text output???

Expand Post »
can someone teach me or show me how to code a program that can output color text?? thx :p
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kakilang is offline Offline
22 posts
since Oct 2004
Oct 26th, 2004
0

Re: How to code a program that can show color text output???

This is an implementation-dependent operation. Without knowing your platform and compiler, we can't help you at all.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 27th, 2004
0

Re: How to code a program that can show color text output???

i am using dev c++ 4.9.9 compiler and windows xp

below is a simple source code

#include<iostream>
using namespace std;

int main()
{
cout<<"Hello"<<endl;
system("pause");
return 0;
}

how to let the program print the "hello" string with color and also how to set the background color??
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kakilang is offline Offline
22 posts
since Oct 2004
Oct 27th, 2004
0

Re: How to code a program that can show color text output???

Search MSDN for SetConsoleTextAttribute.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 27th, 2004
0

Re: How to code a program that can show color text output???

still can't understand can u show me some example source code
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kakilang is offline Offline
22 posts
since Oct 2004
Oct 27th, 2004
0

Re: How to code a program that can show color text output???

>still can't understand can u show me some example source code
No, why don't you try experimenting instead of mooching off everyone else. This isn't a terribly difficult task, and by working it out on your own you'll learn much more than if I just gave you code to copy.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Oct 27th, 2004
0

Re: How to code a program that can show color text output???

i really dun understand all the things in MSDN
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kakilang is offline Offline
22 posts
since Oct 2004
Oct 27th, 2004
0

Re: How to code a program that can show color text output???

Looks like Narue is in the usual good mood this morning.
You have to forgive! Good person though!

I took BCX, the basic to C translator, and figured it out in 5 minutes flat. Here is the C code. You may throw in a little C++ lingo. The name of the WinApi header may be different with your compiler. Play with k a little to get the feel!
  1. // change text color in Windoze console mode
  2. // colors are 0=black 1=blue 2=green and so on to 15=white
  3. // colorattribute = foreground + background * 16
  4. // to get red text on yellow use 4+14*16
  5. // tested with Pelles C (vegaseat)
  6.  
  7. #include <stdio.h>
  8. #include <windows.h> // or other WinApi header
  9.  
  10.  
  11. int main()
  12. {
  13. HANDLE hConsole;
  14. int k;
  15.  
  16. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  17.  
  18. for(k = 1; k < 25; k++)
  19. {
  20. SetConsoleTextAttribute(hConsole, k);
  21. printf("%2d %s\n", k, "I want to be nice today!");
  22. }
  23.  
  24. getchar(); // cheap wait
  25. return 0;
  26. }
Actually, programming can be fun ...
a man, sorry, person over machine thing!
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Oct 28th, 2004
0

Re: How to code a program that can show color text output???

thx for ur help vegaseat.

Do u know how to let the text in the program blink???
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kakilang is offline Offline
22 posts
since Oct 2004
Oct 28th, 2004
0

Re: How to code a program that can show color text output???

Do you now see what happens vegaseat? If you give them the answer then they'll stop thinking for themselves--assuming they thought for themselves in the first place--and expect you to continue giving them the answer. The goal here is not to solve the problems of others, but to teach others how to solve their own problems.

>Do u know how to let the text in the program blink???
I know how to make text blink, but I'm not going to tell you because one method is easy to figure out using what you just learned.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in C Forum Timeline: algorithm uses in scheduling between RAM and CPU
Next Thread in C Forum Timeline: Open GL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC