|
发表于 2005-3-19 17:01:02
|
显示全部楼层
toupper-Convert a character to uppercase
Synopsis
#include <ctype.h>
cc = toupper(c);
int cc; /* converted character */
int c; /* character to convert */
Description
The toupper function is the reverse of the tolower function.
You can use either characters or integers as arguments, but the
macro is defined only over the integer range from -1 to 255. The
function, however, will return a result for values above 255, but
the results are not necessarily correct and cannot be relied upon.
The reason -1 is included as a valid argument is to avoid a
nonsensical result if you feed the EOF value to one of the macros
or functions. EOF can be returned by the getchar function and
other I/O functions, and if you pass it to any of the character
test functions, the return value will be 0.
If you include the file ctype.h as shown above, this function is
actually defined as a macro and produces inline code to perform
the conversion. Without the ctype.h file, it is an actual
function resolved in the standard library. If you want to use the
function version but must include the file ctype.h for some other
reason, use an #undef statement to undefine the macros after
including the ctype.h file.
#undef toupper
Example
/*
* The following program echoes each input
* line in upper case.
*/
#include <stdio.h>
#include <ctype.h>
void main(void)
{
char b[256],*p;
while(gets(b) != NULL)
{
for (p = b; *p != '0'; p++)
{
*p = toupper(*p);
}
puts(b);
}
} |
|