Tuesday, 4 February 2014

Lex program to convert lowercase to uppercase

Lex program to convert lowercase to uppercase:
This program takes a string from the text file and convert every letter into the reverse case of it and display every character.

Program:
lower [a-z]
upper [ A-Z]
%%

{lower} { printf(" % c",yytext[0]-32);
{upper} {printf("%c",yytext[0]+32);
[\t\n]+  echo;
. echo;

%%
main( )
{
yylex();
}

Output: 
$ lex ex1.l
$ gcc ex1.c -ll
$ ./a.out<untitled.txt
mY NAME IS kHAN
gaurav singh pundir
$

and the untitled.txt file contains:
My name is Khan
GAURAV SINGH PUNDIR

 
 
 
 

No comments:

Post a Comment