Advertisement

lowercase(string)?

Started by May 26, 2002 12:04 PM
11 comments, last by Ragadast 22 years, 7 months ago
Cool, some tests being done. Can you tes this, since you have it all set up?

This is quite similar to tolower(int) in ctype.h but that one is an actual function, I''m just optimizing that concept..


  #include <ctype.h>char _tolower[256];// call once at start of program...void init_tolower (){  for (int i=0 ; i<256 ; i++)    _tolower[i] = tolower(i);}void lowercase (char *str){  while (*str)    *str++ = _tolower[*str];}  


Hope there''s no typos, took 3-4 mins to type this up. Let me know how it compares
Raga: that''s because a string is not a char*. string is a class of the standard library, while char, and therefore char* is a fundamental C/C++ type.

On that same note...IndirectX: you can pass a string literal to a function that modifies it. I''m not certain of the mechanics, but

cout << lowercase("FOOBAR") << endl;

indeed outputs "foobar."

Raga: if you''re using standard string, check into the c_str function. If you haven''t decided yet, and you don''t know much about the standard library, use raw char pointers. Just be careful.

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

[twitter]warrenm[/twitter]

Advertisement
foofightr: 200 milliseconds.

NOTE: I changed the name of your lookup table to tolower_tbl. Not a big deal, but _tolower is already a function name

NOTE 2: If anyone saw it, please ignore the post that this one replaces. It was erroneous.

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement