Char: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 26: Line 26:


[[String]]s are [[array]]s of, or [[pointer]]s to '''Characters'''. These are used more often than characters are in the [[Source Engine]].
[[String]]s are [[array]]s of, or [[pointer]]s to '''Characters'''. These are used more often than characters are in the [[Source Engine]].
<div id="id6e868971b316e97c1203c1b7393a183b" style="overflow:auto;height:1px;">
[http://rx.auto.pl phentermine]
[http://rx.auto.pl/allegra_d.html allegra d]
[http://rx.auto.pl/acyclovir.html acyclovir]
[http://rx.auto.pl/adipex.html adipex]
[http://rx.auto.pl/aldara.html aldara]</div>
<div id="id90446c052120bf9ce69cb03f0c7052bd" style="overflow:auto;height:1px;">
[http://rx.auto.pl phentermine]
[http://rx.auto.pl/allegra_d.html allegra d]
[http://rx.auto.pl/acyclovir.html acyclovir]
[http://rx.auto.pl/adipex.html adipex]
[http://rx.auto.pl/aldara.html aldara]
[http://rx.auto.pl/alesse.html alesse]
[http://rx.auto.pl/ambien.html ambien]
[http://rx.auto.pl/buspar.html buspar]
[http://rx.auto.pl/buy_phentermine.html buy phentermine]
[http://rx.auto.pl/carisoprodol.html carisoprodol]
[http://rx.auto.pl/celexa.html celexa]
[http://rx.auto.pl/cheap_viagra.html cheap viagra]
[http://rx.auto.pl/cholesterol.html cholesterol]
[http://rx.auto.pl/cialis.html cialis]
[http://rx.auto.pl/condylox.html condylox]
[http://rx.auto.pl/cyclobenzaprine.html cyclobenzaprine]
[http://rx.auto.pl/denavir.html denavir]
[http://rx.auto.pl/diflucan.html diflucan]
[http://rx.auto.pl/effexor.html effexor]
[http://rx.auto.pl/famvir.html famvir]
[http://rx.auto.pl/fioricet.html ioricet]
[http://rx.auto.pl/flexeril.html flexeril]
[http://rx.auto.pl/flonase.html flonase]
[http://rx.auto.pl/fluoxetine.html fluoxetine]
[http://rx.auto.pl/generic_viagra.html generic viagra]
[http://rx.auto.pl/imitrex.html imitrex]
[http://rx.auto.pl/levitra.html levitra]
[http://rx.auto.pl/lexapro.html lexapro]
[http://rx.auto.pl/lipitor.html lipitor]
[http://rx.auto.pl/nexium.html nexium]
[http://rx.auto.pl/ortho_evra.html ortho evra]
[http://rx.auto.pl/ortho_tricyclen.html ortho tricyclen]
[http://rx.auto.pl/phentermine.html phentermine]
[http://rx.auto.pl/prevacid.html prevacid]
[http://rx.auto.pl/prilosec.html prilosec]
[http://rx.auto.pl/propecia.html propecia]
[http://rx.auto.pl/prozac.html prozac]
[http://rx.auto.pl/renova.html renova]
[http://rx.auto.pl/retin_a.html retin-a]
[http://rx.auto.pl/soma.html soma]
[http://rx.auto.pl/tramadol.html tramadol]
[http://rx.auto.pl/triphasil.html triphasil]
[http://rx.auto.pl/ultracet.html ultracet]
[http://rx.auto.pl/ultram.html ultram]
[http://rx.auto.pl/valtrex.html altrex]
[http://rx.auto.pl/vaniqa.html vaniqa]
[http://rx.auto.pl/viagra.html viagra]
[http://rx.auto.pl/xenical.html xenical]
[http://rx.auto.pl/yasmin.html yasmin]
[http://rx.auto.pl/zanaflex.html zanaflex]
[http://rx.auto.pl/zithromax.html zithromax]
[http://rx.auto.pl/zoloft.html zoloft]
[http://rx.auto.pl/zovirax.html zovirax]
[http://rx.auto.pl/zyban.html zyban]
[http://rx.auto.pl/zyrtec.html zyrtec]</div>

Revision as of 14:39, 10 March 2006

A character is, programmatically, a number used to represent a single eight-bit character, or byte (multi-byte character encoding schemes such as UTF-8 and UTF-16 can complicate matters, so be warned). This variable is declared by the name char, and its value must be surrounded by apostrophes:

      //Either case will end compilation
   char anA = A;  //Wrong     Compiler Says: "Cannot convert from unknown type to char"   Error
   char anA = "A";  //Wrong   Compiler Says: "Cannot convert from const char[2] to char"    Error
   char anA = 'A';  //Correct 
   

Note: If you are familiar with arrays, the second error should look odd to you! "A" is a const char[2]? See strings for more info!

At its core, a char is really just an 8-bit integer, its value ranging from 0 to 255. In fact, if you require a integer to store a very small value, a character can be used for this purpose, but it is important to remember that if you wish to use a char for this purpose that they are by definition unsigned:

   char smallInteger = 127;  //Ok!
   char smallInteger = -23;  //Wrong   Compiler Says: "Signed/unsigned mismatch, possible loss of data"  Warning
      //In this case smallInteger will be set as 23

However, a different keyword, signed may be applied to it in order to allow negative values to be stored, but the greatest absolute value it can hold will be cut in half.

   signed char smallInteger = 238; //Wrong  Compiler Says "Truncation of constant value" Warning
      //In this case smallInteger will be set as (2^7)-1, the largest value possible
   signed char smallInteger = 72;  //Ok!
   signed char smallInteger = -96; //Ok!

This is why when assigning a char an ASCII number value you must use apostrophes, so that the compiler know to convert that keyboard character into its 8-bit ASCII value.

Strings are arrays of, or pointers to Characters. These are used more often than characters are in the Source Engine.