Browsed by
Tag: converting string

Converting a string to upper case

Converting a string to upper case

This function converts strings into upper case in C language. It is a simple one. I use ternary operator.
Code:

void UppCase(Char *str)
{
while(*str!=0)//traversing until end of atring

/* check whether the char is between ‘a’ and ‘z’. If it is subtract the ASCII value of ‘a’ and add ASCII value of ‘A’. Otherwise print the char as it is */

*str = (*str>=’a’ && *str <= ‘z’)?(*str-‘a’+’A’):*str;
str++;//increment pointer to next position
}