Is there a good example of how toupper() works?

George Turczynski george at hls0.hls.oz
Wed Oct 24 09:29:52 AEST 1990


In article <2466 at ux.acs.umn.edu>, edh at ux.acs.umn.edu (Eric "The Mentat Philosopher" Hendrickson) writes:
> Basically, what I want to do is take a string of upper/lower case, and make
> it all upper case.  Here is a first try at it,
> 
> [Code deleted]
> 
> Can anybody point out a good way of doing this?

Since people have already commented on the oversights (?) in your code, I won't
add any more.  So here's a piece of code that does the trick, but is perhaps
best implemented as a function:


/* --- Cut here --- */

#include<stdio.h>
#include<ctype.h>

main()
{
	char *work, *duh= "Hello";

	printf("%s\n",duh);

	/* The important piece follows... */

	for( work= duh; *work; work++ )
		if( islower(*work) )
			*work= toupper(*work);
	
	/* That was it ! */

	printf("%s.\n",duh);

	exit(0);
}

/* --- Cut here --- */

I hope that this might help you to solve your problem.  Have a good day...


-- 
George P. J. Turczynski,   Computer Systems Engineer. Highland Logic Pty Ltd.
ACSnet: george at highland.oz |^^^^^^^^^^^^^^^^^^^^^^^^| Suite 1, 348-354 Argyle St
Phone:  +61 48 683490      |  Witty remarks are as  | Moss Vale, NSW. 2577
Fax:    +61 48 683474      |  hard to come by as is | Australia.
---------------------------   space to put them !    ---------------------------



More information about the Comp.lang.c mailing list