The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

strupr() In C

Purpose of strupr()

strupr() is one of the inbuilt string function in c programming which is used to converts the lowercase characters to UPPERCASED characters.

How strupr() Works

The following diagram clearly illustrate the working principle of strupr() inbuilt string function in C.

strupr() in c

In the above diagram strupr() takes a single parameter which is of string type. strupr() will transform all lowercased characters to UPPERCASED characters.

Syntax - strupr()

  • strupr() accepts one parameter.
  • Parameter must be a string.
  • To use strupr() inbuilt string function in C, we need to declare #include<string.h> header file.
Syntax
strupr(str);

C Program - strupr()

Let us work through strupr() function. In the following program we will transform all lowercased characters to UPPERCASED characters by using strupr() inbuilt string function.

c-using-strupr.c
#include <stdio.h>
#include<string.h>
int main()
{
char str[30] = "this is strupr";
printf("The string in uppercase : %s ", strupr(str));
return 0;
}
THIS IS STRUPR

Note:

The above program prints the uppercase letters of a string str.

C Program - Without strupr()

Let us transform all lowercased characters to UPPERCASED characters in a string without using inbuilt string function strupr().

c-without-strupr.c
#include <stdio.h>
#include<string.h>
int main()
{
char str[30] = "this is strupr", i;
for(i=0; str[i]!='\0';i++)
{
if(str[i]!=32){
// filtering blank space
printf("%c",str[i]-32);
}
else
printf(" ");
}
return 0;
}
THIS IS STRUPR

Note:

The above program looks verbose but yields same the result.

Did You Know?

When a string containing '\0' in its middle i.e) This\0willbreak, then strlen() will break and return the count upto '\0' i.e) it returns 4.

c-strupr-3.c
#include <stdio.h>
#include<string.h>
int main()
{
char str1[] = "This\0willbreak";
printf("Length of str1 = %d ", strlen(str1));
return 0;
}
Length of str1 = 4

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report