C Programming Language

string function : strupr()

Syntax:
char * strupr(char *str);

strupr(str) coverts str to all uppercase. It returns a pointer to the original input string str.

This function will convert all the lowercase characters in the string, which is provided as parameter, into uppercase. It will convert every lowercase to uppercase.

For example

#include<stdio.h>
#include<conio.h>
int main()
{   
    char str[30]="www.CProgrammingExpert.com";           
    clrscr();
    printf("str : %s\n",str);
    printf("strupr(str) : %s\n",strupr(str));
    getch();
    return 0;
}

here we declares the string str like this str[30]="www.CProgrammingExpert.com"; The string string str is a character array of size 30.The character is stored like this

str[0] <- 'w'
str[1] <- 'w'
str[2] <- 'w'
str[3] <- '.'
str[4] <- 'C'
str[5] <- 'P'
str[6] <- 'r'
str[7] <- 'o'
str[8] <- 'g'
str[9] <- 'r'
str[10]  <-'a'                   
str[11]  <-'m'   
str[12]  <-'m'   
str[13]  <-'i'   
str[14]  <-'n'   
str[15]  <-'g'   
str[16]  <- 'E' 
str[17]  <- 'x'
str[18]  <- 'p'
str[19]  <- 'e'
str[20]  <- 'r'
str[21]  <- 't'
str[22]  <- '.'
str[23]  <- 'c'
str[24]  <- 'o'
str[25]  <- 'm'
str[26]  <- '\0'
str[27]  <- 'garbage value'
str[28]  <- 'garbage value'
str[29]  <- 'garbage value'

whe we use the function strupr(str) it will convert all characters stored in the character array str to uppercase.Then stored like this

str[0] <- 'W'
str[1] <- 'W'
str[2] <- 'W'
str[3] <- '.'
str[4] <- 'C'
str[5] <- 'P'
str[6] <- 'R'
str[7] <- 'O'
str[8] <- 'G'
str[9] <- 'R'
str[10]  <-'A'                   
str[11]  <-'M'   
str[12]  <-'M'   
str[13]  <-'I'   
str[14]  <-'N'   
str[15]  <-'G'   
str[16]  <- 'E' 
str[17]  <- 'X'
str[18]  <- 'P'
str[19]  <- 'E'
str[20]  <- 'R'
str[21]  <- 'T'
str[22]  <- '.'
str[23]  <- 'C'
str[24]  <- 'O'
str[25]  <- 'M'
str[26]  <- '\0'
str[27]  <- 'garbage value'
str[28]  <- 'garbage value'
str[29]  <- 'garbage value'

so after using the function strupr(str) the value of string str is"WWW.CPROGRAMMINGEXPERT.COM"

Example:

strlen() function  
strlwr() Home strcat()

c program stats