Links to ASCII values:Originally Posted by Skillachi
www.lookuptables.com
www.newebgroup.com/rod/newillusions/ascii.htm
Links to ASCII values:Originally Posted by Skillachi
www.lookuptables.com
www.newebgroup.com/rod/newillusions/ascii.htm
There is no wrong or right, only consequencies to action
"It is the duty of man to make his knowledge so complete in life, so as to make it impossible for any other to take advantage of him" - Marcus Garvey
thats easy write this code in borland and run it.
when u run it just hit any key on the keyboard.. it will print the ascii number. the function keys like F1 and so forth sends two asccii numbers but they all start with 0.Code:int main() { char c; while(1) { c = getch(); printf("%d\n", c); } }
note: the program will loop forever until you terminate it.. just close the console window or tyr pressing ctrl + c.
yea.. upper case letters have different ascii numbers from their lowersace equivalent. you could look at the link tjrak posted or you could hold down shift key will you hit the keys with the code i postedOriginally Posted by Skillachi
Man... that code there stink... i will now begin to pwn all in C
Laptop: HP DV6700t - Core 2 Duo T9300 2.5Ghz, 3GB RAM, Nvidia 8400m GS, 250GB HDD. Ubuntu 12.04 and Windows 7
Phone: Samsung Galaxy Nexus
What do u use to change the colour of the font in C++?Originally Posted by leoandru
The views expressed in the above post are not neccesarily the views of icuucme.
uhmm, what you must know is that these functions used in both c and C++ are not part of ANSI/ISO standard. must of these are funtions are supplied with the compiler. The function i posted (about changing the textcolor) before only works with the borland compiler and not on the windows c compiler. The code im about to post definately works on the windows compiler because I tested it b4 i posted but im not sure if it will work on the borland compiler. If the borlands windows.h library is compatible with the windows version then it should work. here goes.Originally Posted by icuucme
this is a fairly simply program. I used a Color class to store the color, as you can see the colors are made up of a mixture the colors: FOREGROUND_RED, FOREGROUND_GREEN, FOREGROUND_BLUE and FOREGROUND_INTENSITY. TheCode:#include <windows.h> #include <iostream> using std::cout; class Color { friend std::ostream& operator<<(std::ostream& stream,const Color& c); public: Color(unsigned short c): color(c) {} unsigned short color; }; std::ostream& operator<<(std::ostream& stream,const Color& c) { stream.flush(); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c.color); stream.flush(); return stream; } const Color RED = FOREGROUND_RED|FOREGROUND_INTENSITY; const Color BLUE = FOREGROUND_BLUE|FOREGROUND_INTENSITY; int main() { cout << RED << "This is red." << BLUE << "\nThis is blue.\n"; getchar(); return 0; }
<< stream operator was overloaded to set the console text color before we do any printing. Basically that set of function calls will have to be called everytime you need to change the color.
Let me know if it works in borland if not tell me the errors you got.
Oh i guess you figured that the.
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE),c.color); is all you need to change the textcolor
update:
The STD_OUTPUT_HANDLE has no spaces i tried editing the post several times but the spaces remained.
Last edited by leoandru; Mar 25, 2005 at 01:26 AM.
It works for me
MS VC 6++
WinXP
The code does not work in Borland for meOriginally Posted by leoandru
I'm using Borland c++ Version 5.02
The views expressed in the above post are not neccesarily the views of icuucme.
could you post a copy of the compile error?
First I got these errors:
Info :Compiling C:\DOCUMENTS AND SETTINGS\myusername\...\BIN\noname01.cpp
Error: noname01.cpp(4,5):Qualifier 'std' is not a class or namespace name
Error: noname01.cpp(4,7):Identifier expected
Error: noname01.cpp(9,19):Qualifier 'std' is not a class or namespace name
Error: noname01.cpp(9,21): Declaration terminated incorrectly
Error: noname01.cpp(16,8):Qualifier 'std' is not a class or namespace name
Error: noname01.cpp(16,10): Declaration terminated incorrectly
Error: noname01.cpp(28,13):Undefined symbol 'RED'
Error: noname01.cpp(29,10):Call to undefined function 'getchar'
After i modified the code to this:
I got the error:Code:#include <windows.h> #include <iostream.h> class Color { friend ostream& operator<<(ostream& stream,const Color& c); public: Color(unsigned short c): color(c) {} unsigned short color; }; ostream& operator<<(ostream& stream,const Color& c) { stream.flush(); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),c.color); stream.flush(); return stream; } const Color RED = FOREGROUND_RED|FOREGROUND_INTENSITY; const Color BLUE = FOREGROUND_BLUE|FOREGROUND_INTENSITY; int main() { cout << RED << "This is red." << BLUE << "\nThis is blue.\n"; getchar(); return 0; }
Info :Compiling C:\DOCUMENTS AND SETTINGS\myusername\...\BIN\noname01.cpp
Error: noname01.cpp(29,10):Call to undefined function 'getchar'
NB: I'm new to c++
Last edited by icuucme; Mar 27, 2005 at 11:15 AM.
The views expressed in the above post are not neccesarily the views of icuucme.