ADVERTISEMENT
ADVERTISEMENT

C program to convert string into lowercase and uppercase without using library function

In this program, we will learn how to implement our own strlwr() and strupr() function in C language?

This program will read a string from the user (string can be read using spaces too), and convert the string into lowercase and uppercase without using the library function.

Here we implemented two functions

  1. stringLwr() - it will convert string into lowercase
  2. stringUpr() - it will convert string into uppercase

Program to convert string into lowercase and uppercase without using library function in C

#include <stdio.h>
 
 
/********************************************************
    *   function name       :stringLwr, stringUpr
    *   Parameter           :character pointer s
    *   Description         
        stringLwr   - converts string into lower case
        stringUpr   - converts string into upper case
********************************************************/
void stringLwr(char *s);
void stringUpr(char *s);
 
int main()
{
    char str[100];
 
	printf("Enter any string : ");
    scanf("%[^\n]s",str);//read string with spaces
    
    stringLwr(str);
    printf("String after stringLwr : %s\n",str);
    
    stringUpr(str);
    printf("String after stringUpr : %s\n",str);
    return 0;
}
 
/******** function definition *******/
void stringLwr(char *s)
{
    int i=0;
    while(s[i]!='\0')
    {
        if(s[i]>='A' && s[i]<='Z'){
            s[i]=s[i]+32;
        }
        ++i;
    }
}
 
void stringUpr(char *s)
{
    int i=0;
    while(s[i]!='\0')
    {
        if(s[i]>='a' && s[i]<='z'){
            s[i]=s[i]-32;
        }
        ++i;
    }
}

Output

Enter any string : Hello friends, How are you?
String after stringLwr : hello friends, how are you?
String after stringUpr : HELLO FRIENDS, HOW ARE YOU? 

C Strings User-defined Functions Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.