Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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? 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now