 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
server Guest
|
Posted: Fri Jan 27, 2006 9:13 pm Post subject: Help! Need to make my own color... |
|
|
message unavailable |
|
| Back to top |
|
 |
Malcolm Guest
|
Posted: Fri Jan 27, 2006 9:13 pm Post subject: Re: Help! Need to make my own color... |
|
|
"arun" <deostroll (AT) gmail (DOT) com> wrote
| Quote: |
I have 3 compilers at home: MSVC++, DEV-C++, and Turbo C++ 3.0.
I would like to know how to make a color of my choice by specifying RGB
values. Perhaps MSVC++, Dev- C++ have their own libraries to do so.
Well, I would like to hear of that...
I am also kind of a knowledge seeker. I would like to know how to
actually make programs to create a color of your choice by specifying
RGB values. I work a lot with turbo c++ graphics. If anyone here knows
how to help me, it would be great.
An image is basically this |
struct colour
{
unsigned char red;
unsigned char green;
unsigned char blue;
};
struct image
{
int width;
int height;
struct colour *pixels;
}
Now you can manipulate this data in a totally portable way. For instance you
could write a routine to turn a full-colour image to black and white, by
changing all the pixels to an average value of grey.
To view it, you need to save it in an image format. Look up wotsit .org for
your favourite image format. (Choose a simple one, not GIF or JPEG, for a
first attempt). |
|
| Back to top |
|
 |
Richard Heathfield Guest
|
Posted: Fri Jan 27, 2006 11:25 pm Post subject: Re: Help! Need to make my own color... |
|
|
Malcolm said:
| Quote: | An image is basically this
struct colour
{
unsigned char red;
unsigned char green;
unsigned char blue;
};
|
Wot, no alpha channel?!?
:-)
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously) |
|
| Back to top |
|
 |
Malcolm Guest
|
Posted: Sat Jan 28, 2006 12:55 am Post subject: Re: #include in header file for size_t |
|
|
"Keith Thompson" <kst-u (AT) mib (DOT) org> wrote .
| Quote: | Pedro Graca <hexkid (AT) dodgeit (DOT) com> writes:
Can this be an exception to the rule about not including header files in
header files?
Where did you get the idea that there's such a rule?
There's nothing wrong with including header files in header files.
Do it if you need to, don't do it if you don't.
I've never found a good answer to this one. |
If you follow a policy of never allowing nested inclusions, then you have a
list of dependencies at the top of each source file.
You also have a list, in reverse order, of the files in call hierarchy.
The problem is that quite often, in video games, you need a "world".
Everything depends on the world, but it also contains everything.
Therefore my function
move_invader(INVADER *baddy, WORLD *wld)
take the world as a parameter, becase the invader needs to update its
position within it.
We will want all the invader functions, like invader_fire, invader_die,
invader_land_and_take_over_Earth in the same invader.c file.
However the world looks like this
typedef struct
{
INVADER *invaderlist;
int width;
int height;
CELL *cells;
SHIP *goody;
} WORLD;
So the easiest thing is to include the definitions of INVADER, CELL, and
SHIP as nested includes in world.h
That means that every file in the program includes "world.h" and no other
headers, and any sense of hierarchy is lost. |
|
| Back to top |
|
 |
Malcolm Guest
|
Posted: Sat Jan 28, 2006 12:55 am Post subject: Re: Professional C software |
|
|
"Nikesh" <nike83 (AT) gmail (DOT) com> wrote in message
| Quote: | Thanks Ivan Kelly
i m trying to get into this industry as soon as possible
i have used VB but people say C is there to remain for long time
VB is not that much popular
let us see what happens
I think Visual Basic is now basic.net, or something. |
The Microsoft-specific programming languages are very popular, and a good
choice if you want to develop business-style applications on PCs only.
If you want to move beyond that world, you must learn another language, and
C is the most obvious choice. C is a general-purpose programming language,
and has stood the test of time better than almost any other language. |
|
| Back to top |
|
 |
Martin Ambuhl Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: reda4win released |
|
|
pablo reda wrote:
| Quote: | what is keen ?
English is not my native lenguaje, sorry.
|
[Concise Oxford English Dictionary, 10th edition]
keen1
· adj.
1 eager; enthusiastic. Ø (keen on) interested in or attracted by.
2 (of the edge or point of a blade) sharp. Ø (of a sense or mental
faculty) acute or quick. Ø (of the air or wind) cold and biting.
3 Brit. (of prices) very low; competitive.
– DERIVATIVES keenly adv. keenness n.
– ORIGIN OE cUne ‘wise, clever’, also ‘brave, daring’, of Gmc origin.
keen2
· v. wail in grief for a dead person. Ø make an eerie wailing sound.
· n. an Irish funeral song accompanied with wailing in lamentation for
the dead.
– DERIVATIVES keener n.
– ORIGIN C19: from Ir. caoinim ‘I wail’. |
|
| Back to top |
|
 |
Keith Thompson Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: reda4win released |
|
|
"pablo reda" <pabloreda (AT) gmail (DOT) com> writes:
| Quote: | what is keen ?
English is not my native lenguaje, sorry.
|
It doesn't really matter. rayw was quoting from a comedy movie.
There are a number of on-line dictionaries, but knowing what "keen"
means isn't going to help you much, and I'm not going to explain the
joke.
What he really meant is that this newsgroup, comp.lang.c, is for
discussion of the C programming language. Announcements of other
languages are inappropriate here. (The language you used to implement
it is irrelevant; it *might* be relevant if you want to discuss *how*
you implemented it.)
Also, please read <http://cfaj.freeshell.org/google/>.
--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. |
|
| Back to top |
|
 |
pablo reda Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: reda4win released |
|
|
| mi program is plain c, gcc compiled with devcpp and SDL library |
|
| Back to top |
|
 |
Flash Gordon Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: second largest element in an array |
|
|
Mark McIntyre wrote:
| Quote: | On 27 Jan 2006 11:03:41 -0800, in comp.lang.c , "tedu"
tu (AT) zeitbombe (DOT) org> wrote:
Mark McIntyre wrote:
system( sprintf (mstr,
"sort -n -u %s | tail -2 | head -1 > result.txt",
file_of_data);
converting sprintf's return to a char * is unlikely to work correctly
on most systems.
I agree, but then a) the entire answer was almost certainly not what
the OP wanted and b) if we posted 100% accurate code in response to
homework questions, nobody would ever learn.
|
You forgot c) on the Psychic Station 200 undefined behaviour does what
the user wants, so on the PS200 it will give the OP the largest two
elements
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it. |
|
| Back to top |
|
 |
Joe Wright Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: Second Highest number in an array |
|
|
Jaspreet wrote:
| Quote: | I was working on some database application and had this small task of
getting the second highes marks in a class. I was able to do that using
subqueries.
Just thinking what is a good way of getting second highest value in an
integer array. One method I know of is to make the 1st pass through the
array and find the highest number. In the second pass we can find the
highest number which is less than the number we obtained in the 1st
pass.
However there has to be a better and more efficient way of doing this.
Please just let me know some hints and I would try it on my own in C.
Thanks and have an enjoyable weekend.
|
#include <stdio.h>
int main(void) {
int pri, sec, i, v;
int arr[] = {4,10,3,8,6,7,2,7,9,2,0};
pri = sec = 0;
for (i = 0; arr[i]; ++i) {
v = arr[i];
if (v > pri) sec = pri, pri = v;
if (v > sec && v < pri) sec = v;
}
printf("pri is %d, sec is %d\n", pri, sec);
return 0;
}
One trip through the array.
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- |
|
| Back to top |
|
 |
pablo reda Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: reda4win released |
|
|
what is keen ?
English is not my native lenguaje, sorry. |
|
| Back to top |
|
 |
Mark McIntyre Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: second largest element in an array |
|
|
On 27 Jan 2006 11:03:41 -0800, in comp.lang.c , "tedu"
<tu (AT) zeitbombe (DOT) org> wrote:
| Quote: | Mark McIntyre wrote:
system( sprintf (mstr,
"sort -n -u %s | tail -2 | head -1 > result.txt",
file_of_data);
converting sprintf's return to a char * is unlikely to work correctly
on most systems.
|
I agree, but then a) the entire answer was almost certainly not what
the OP wanted and b) if we posted 100% accurate code in response to
homework questions, nobody would ever learn.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =---- |
|
| Back to top |
|
 |
Joe Wright Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: Bit-fields and integral promotion/UACs |
|
|
Christian Kandeler wrote:
| Quote: | Alex Fraser wrote:
The shift invokes undefined behaviour, because the left-hand operand has
signed type and the result cannot be represented in that type.
Don't you mean "cannot _necessarily_ be represented"? Surely if int is 32
bits, then 1 << 31 is okay? Or, more generally, 1 << sizeof int * CHAR_BIT
- 1 is? If not, I'd be interested to know why.
Christian
|
It's the old off-by-one problem.
1 << 31 yields..
1000 0000 0000 0000 0000 0000 0000 0000 Min int = -2147483648
...and MAX_INT is..
0111 1111 1111 1111 1111 1111 1111 1111 Max int = 2147483647
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- |
|
| Back to top |
|
 |
Keith Thompson Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: Bit-fields and integral promotion/UACs |
|
|
Christian Kandeler <christian (AT) kandeler (DOT) de> writes:
| Quote: | Alex Fraser wrote:
The shift invokes undefined behaviour, because the left-hand operand has
signed type and the result cannot be represented in that type.
Don't you mean "cannot _necessarily_ be represented"? Surely if int is 32
bits, then 1 << 31 is okay? Or, more generally, 1 << sizeof int * CHAR_BIT
- 1 is? If not, I'd be interested to know why.
|
If int is 32 bits, the INT_MAX is 2147483647.
1 << 31 is 2147483648.
--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. |
|
| Back to top |
|
 |
Keith Thompson Guest
|
Posted: Sat Jan 28, 2006 1:26 am Post subject: Re: how do increment operations work |
|
|
"pai" <grpai1 (AT) yahoo (DOT) com> writes:
| Quote: | Sorry for not having a clear english dialect.
|
Context: This was about the "doubt" vs. "question" thing. We've seen
that enough around here that we're (sort of) getting used to it, but
using "question" will make it easier to understand.
| Quote: | I am not able to understand how is the increment works in program 1
and in program 2 why there is a compile error.
here is the code..
---------------------------------------
Program 1
-------------------------------------
[snip]
ans = ++i + ++i ;
[snip]
ans = ++i + ++i + ++i;
|
I already answered that in the article to which you're replying.
Once again:
] The C FAQ is at <http://www.c-faq.com/>. Read question 3.2.
] Then read the rest of section 3. Then read the rest of the FAQ.
| Quote: | ----------------------------------------
program 2
------------------------------------------------
Another program is
[snip]
ans = ++i ++i ;
[snip]
test1.c:9: error: syntax error before "i"
|
Yes, that's a syntax error. The subexpression "++i" appears twice,
with no operator in between. What were you expecting it to do?
And please read <http://cfaj.freeshell.org/google/> and follow its
advice.
--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|