#### Archived

This topic is now archived and is closed to further replies.

# a realy stupid question, how do I put char constants in my code?

This topic is 5588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

a dumb question I know but I can''t figure it out. example if ( quit == y )break;
MSVC++ 6.0 intro DX 8.0a DX SDK 6.1 win98 #define WIN32_LEAN_AND_MEAN the Particle Projection Cannon fires a shimmering blue bolt, much like a cross between lightning and a sine wave that ripples along its path.

##### Share on other sites

C#
private const int NUM_OF_STUDENTS = 400;

C++

#define NUM_OF_STUDENTS 400

OR

const int NUM_OF_STUDENTS = 400;

For your example though, I would make Quit a boolean.

if(quit) // where quit is an int of 1 or 0
{
// exit;
}

"Wisdom is proportionate to your reference base. Intelligence is the ability to appropriately use that Wisdom."

##### Share on other sites
err.... not sure what Leatherwulfe is talking about, but char constants are like this: ''y''

Don''t listen to me. I''ve had too much coffee.

##### Share on other sites
Character constants must be denoted by apostrophes (single quotes), as such: if(quit == ''y''). (With strings, of course, we use conventional double quotes, so ''y'' is a character, while "y" is a string.)

##### Share on other sites
If (StrCompare(quit, "Y" != 0)
//They were equale
else
//They were not

I''m pretty sure its StrCompare, it might be StrCmpr. Hope that helps, good luck.

##### Share on other sites

  char quit = GetCharFromSomeFunctionOrSomething();if (quit == ''y'')   break;

##### Share on other sites
Whoops, I totally misread his post. Nevermind me

"Wisdom is proportionate to your reference base. Intelligence is the ability to appropriately use that Wisdom."

strcmp

##### Share on other sites
hehe, at least you aren''t suggesting strcmp like all those AP''s

Don''t listen to me. I''ve had too much coffee.

##### Share on other sites
hehe true.

I would do this though, assuming quit is a char:

if(tolower(quit) == 'y')
{
break;
}

That way you are covered if quit = 'y' or 'Y'

"Wisdom is proportionate to your reference base. Intelligence is the ability to appropriately use that Wisdom."

[edited by - Leathrewulfe on August 27, 2002 7:06:22 PM]

##### Share on other sites
strange... the last time I tried ''y'' I got a compile time error. go figure? I glanced through three c tutorials(two I''ve read and the third I''m half way through) for that and I couldn''t find a hint. thanks!

MSVC++ 6.0 intro
DX 8.0a DX SDK 6.1
win98
#define WIN32_LEAN_AND_MEAN
the Particle Projection Cannon fires a shimmering blue bolt, much like a cross between lightning and a sine wave that ripples along its path.

##### Share on other sites
you might have got a compiler error if you are using the other ` , ’ , instead of ' ( I hope these come out right! ). If you want, just hold and type in 39 in the numpad and release in MsDev, Word etc to get the actual char. (39 for UK keyboard char set anyhow ).

[edited by - mark duffill on August 27, 2002 8:23:37 PM]

• ### Forum Statistics

• Total Topics
628696
• Total Posts
2984264

• 18
• 9
• 13
• 13
• 11