C Program to Convert String to Uppercase Using User Defined Function

This C program converts all lowercase letters in the given string to uppercase using user defined function and without using string handling function strupr().

C Source Code: String to Uppercase User Defined Function


#include<stdio.h>

/* Function Prototype */
void mystrlwr(char str[40]);

/* Main Function */
void main()
{
 char str[40];
 int i;

 printf("Enter string:\n");
 gets(str);
 mystrlwr(str);
 printf("String in uppercase is:\n");
 puts(str);
 
 return 0;
}

/* Function Definition */
void mystrlwr(char str[40])
{
 int i;
 for(i=0;str[i]!='\0';i++)
 {
  if(str[i]>='A'&& str[i]<='Z')
  {
   str[i] = str[i]+32;
  }
 }
}

Output

Enter string:
WeLcOmE To C 101. ↲
String in lowercase is:
WELCOME TO C 101.

Note: ↲ represents ENTER key is pressed.