Mail Archives: djgpp/1997/12/30/22:45:44
Visionary wrote:
<snip>
> Also, I couldn't use the parameter "compoundMode" directly as
> in:
>
> newCompoundMode = strlwr(&compoundMode);
>
> This gives me the above mentioned crash and burn as well. Any
> ideas on either of these two weird quirks?
why is it that every time someone makes a mistake it is a 'quirk'?
compoundMode is a single char. strlwr expects a char * to a
null-terminated string. when you pass it the address of that single
char, there is no guarantee that the next byte will contain '\0'. so, if
that value is not '\0', strlwr continues to convert to lower case,
overwiriting memory locations until it meets a '\0'. when it runs into
one depends on how the variables are laid out in memory. so, you get a
crash in one case, and not in the other. the code is equally wrong in
either case.
by the way, why not use the ANSI function tolower whose purpose is to
convert characters to lower case?
info libc alpha tolower
info libc alpha toupper
--
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA
mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/
- Raw text -