Is there a good example of how toupper() works?
Adam Stoller
ghoti+ at andrew.cmu.edu
Wed Oct 17 22:54:28 AEST 1990
Both the original code posted and that as supplied by others - seems to
accept the fact that
char *duh = "Hello";
can be modified. From what I recall, for your simple test function to
work, you would either have to use:
char duh[] = "Hello";
or pass/read in a string into either a malloc'ed area or char array --
before being able to modify it.
Of course I could be wrong - but...for my $0.02 function contribution:
#include <ctype.h>
int main()
{
char duh[] = "Hello"; /* see (1), below */
char *s = NULL;
printf("%s\n", duh);
for (s = duh; *s != '\0'; s++){
*s = toupper(*s); /* see (2), below */
}
printf("%s\n", duh);
}
(1) some older compilers will require this to be declared static, before
allowing you to use aggregate initialization.
(2) under ANSI you don't need to test for islower() - pre-ANSI requires
the islower() test because many of the macros used to define islower and
toupper were brain-dead
--fish
More information about the Comp.lang.c
mailing list