From: Deepesh K. <dee...@gm...> - 2008-03-28 23:27:01
|
hello all, i would like to know if the CHAR datatype is case-sensitive?? i.e. should i write code like this to recognise the character or not e.g. char = category; if (category == 'M') or (category == 'm') cheers.. -- ---Deepesh Kapadia--- |
From: Per W. <pw...@ia...> - 2008-03-28 23:32:17
|
Of course it is case-sensitive. If it wasn't, you wouldn't be able to write any application that must be able to separate upper and lower case. /pwm On Sat, 29 Mar 2008, Deepesh Kapadia wrote: > hello all, > i would like to know if the CHAR datatype is case-sensitive?? > i.e. should i write code like this to recognise the character or not > > e.g. > char = category; > if (category == 'M') or (category == 'm') > > cheers.. > > -- > ---Deepesh Kapadia--- > |
From: Philip B. <phi...@pb...> - 2008-03-28 23:32:44
|
Yes, it is definitely case sensitive. If you have a lot of options to check and a single variable that contains the current one, you could always use the function tolower which will make life a bit easier for you in that case. You just convert it to a lowercase before you start checking and then you don't need to bother about it. Regards Philip Bennefall ----- Original Message ----- From: Deepesh Kapadia To: dev...@li... Sent: Saturday, March 29, 2008 12:20 AM Subject: [Dev-C++] Char datatype hello all, i would like to know if the CHAR datatype is case-sensitive?? i.e. should i write code like this to recognise the character or not e.g. char = category; if (category == 'M') or (category == 'm') cheers.. -- ---Deepesh Kapadia--- ------------------------------------------------------------------------------ ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace ------------------------------------------------------------------------------ _______________________________________________ Dev-cpp-users mailing list Dev...@li... TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
From: hhh h. <the...@ho...> - 2008-03-30 16:47:00
|
deeps6ix Well, even though other estimeed members have already answered this, let me explain why char is case-sensitive; I kinda get the feeling, by your question, you do not fully understand what a char is. The datatype 'char' is a "virtual conception", in that a 'char' = 1 byte, and represents an entry of ASCII table. The 'char' type does not exist in terms that it is really a integer. Every entry of the ASCII table features a value and a charater. the first 31 entries consist of teletype control codes, like carriage return ( legacy typewriter thing, that you had to do when you wanted to change lines. ) The following 96 entries features common letters, numbers and pontuaction stuff. This, obviously represents the first 127 entries, that are, also the maximum value a byte ( signed ) can achive... but looking into ASCII table reveals Value('M') = 77 and Value('m') = 109, therefore 'm' != 'M' Check out this code, execution gives more info : <CODE LANG="C"> #include <stdio.h> int ReturnBytesInChar( unsigned char ch ) { /* Right shhifts bits out, to AND with 0000 0001*/ int i; for ( i=7*sizeof( char ) ; i >=0 ; i-- ) printf("%d", (ch >> i) & 1 ); }int ReturnBytesInInt( unsigned int ch ) { int i; for ( i=7*sizeof(int) ; i >=0 ; i-- ) printf("%d", ( ch >> i ) & 1); } int main () { char a = 'a'; unsigned int aIntegerValue = 97; unsigned int Draw; printf("Is a char = \'a\' equal a int = 97?\n\n"); if ( a == aIntegerValue ) printf("Wow, they do ? WTF!"); else printf("Nah! this guys is full of bollogny"); // This will never happen!!! heheh humor, hehe printf ("\n\nBut.. numbers of bytes allocatted for a char variable are %d and for a integer one %d\n...How can this be?", sizeof(char),sizeof(int)); printf("\n\nSimple dude :\n Check this table :\n"); for ( Draw^=Draw ; Draw != 9+sizeof(int)*7; Draw ++ ) putchar('-'); printf("\n\nChar bytes\t:\t%d\nVarDump:", sizeof( char ) ); ReturnBytesInChar( a ); printf("\n\nInt var bytes\t:\t%d\nVarDump:", sizeof( int ) ); ReturnBytesInInt( aIntegerValue ); putchar(10); for ( Draw^=Draw ; Draw != 9+sizeof(int)*7; Draw ++ ) putchar('-'); printf("\nNotice the similarities ? from the %do byte to the %do of integer the value equals \rchar's %d byte%c\n", sizeof(unsigned int)-1, sizeof(unsigned int), sizeof(char), (sizeof(char)>1) ? 's':' '); printf("What about diferent capitalizations? \'m\' and \'M\'?\nComputer see them as their values, and not letters...\n"); printf("See it as :\n\n\tAs value(\'m\') != value(\'M\') =>(implies)\n\t\t 'M' != 'm' \nAnd we can see it by the same functions above..."); printf("mess with them, and learn... and \rsee functions like fgetc() and try to understand why they are \'buggy\'"); scanf("%c",&a); }</CODE> Date: Sat, 29 Mar 2008 11:20:28 +1200From: dee...@gm...To: dev...@li...Subject: [Dev-C++] Char datatypehello all,i would like to know if the CHAR datatype is case-sensitive??i.e. should i write code like this to recognise the character or note.g. char = category;if (category == 'M') or (category == 'm')cheers..-- ---Deepesh Kapadia--- _________________________________________________________________ Instale a Barra de Ferramentas com Desktop Search e ganhe EMOTICONS para o Messenger! É GRÁTIS! http://www.msn.com.br/emoticonpack |