Showing posts with label Changecase. Show all posts
Showing posts with label Changecase. Show all posts

Convert Lowercase to Uppercase & Reverse - Lex Progam - Compiler Design

CHANGE CASE - LEX - PROGRAM


Program:

// Lex file: cap.l


lower [a-z]
CAPS  [A-Z]
space    [ \t\n]

%%
{lower}         {printf("%c",yytext[0]- 32);}
{CAPS}        {printf("%c",yytext[0]+ 32);}
{space}        ECHO;
.                    ECHO;
%%

main()
{
    yylex();
   
}

Output:
nn@linuxmint ~ $ lex cap.l
nn@linuxmint ~ $ gcc lex.yy.c -ll
nn@linuxmint ~ $ ./a.out<tst.txt
WWW.2K8618.BLOGSPOT.COM
sanjana    jamsheena chaithanya neethu
GOVINDAPRASAD VIPIN ADARSH SHIVIN
baby brinda kavya helen
SALMAN TINU RICHARD  SIBIN
SHIVIN laji NABEEL
www.2k8cse.cu.cc
nn@linuxmint ~ $

// tst.txt

www.2k8618.blogspot.com
SANJANA    JAMSHEENA CHAITHANYA NEETHU
govindaprasad vipin adarsh shivin
BABY BRINDA KAVYA HELEN
salman tinu richard  sibin
shivin LAJI nabeel
WWW.2K8CSE.CU.CC

Change Case of The Letter - C Program

Program:
#include<stdio.h>
//#include<conio.h>
void main()
{
    char c; //clrscr();
    printf("\n\t***A PROGRAM TO CHANGE THE CASE OF THE CHARACTER***\n\n");
    printf("Enter a character:");
    scanf("%c",&c);
    if(c<96)
    {
        printf("\nYou entered the upper case letter '%c' \n\tThe lower case is '%c'.\n",c,c+32);
    }
    else
    {
        printf("\nYou entered the lower case letter'%c' \n\tThe upper case is'%c'.\n",c,c-32);
    }
    //getch();
}

Output:
nn@linuxmint ~ $ gcc CC3.c
nn@linuxmint ~ $ ./a.out

    ***A PROGRAM TO CHANGE THE CASE OF THE CHARACTER***

Enter a character:a

You entered the lower case letter'a'
    The upper case is'A'.
nn@linuxmint ~ $
Related Posts Plugin for WordPress, Blogger...