PROGRAM TO FIND WHETHER STRING IS A KEYWORD OR NOT
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,flag=0,m;
char s[5][10]={"if","else","goto","continue","return"},st[10];
clrscr();
printf("\n enter the string :");
gets(st);
for(i=0;i<5;i++)
{
m=strcmp(st,s[i]);
if(m==0)
flag=1;
}
if(flag==0)
printf("\n it is not a keyword");
else
printf("\n it is a keyword");
getch();
}
OUTPUT
enter the string:return
it is a keyword
enter the string:hello
it is not a keyword
PROGRAM TO FIND WHETHER THE STRING IS CONSTANT OR NOT
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
void main()
{
charstr[10]; int len,a; clrscr();
printf("\n Input a string :");
gets(str); len=strlen(str); a=0; while(a<len)
{
if(isdigit(str[a]))
{
}
else
{
}
}
a++;
printf(" It is not a Constant");
break;
if(a==len)
{
printf(" It is a Constant");
}
getch();
}
OUTPUT
Input a string :23
It is a Constant
Input a string :a_123
It is not a Constant
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,flag=0,m;
char s[5][10]={"if","else","goto","continue","return"},st[10];
clrscr();
printf("\n enter the string :");
gets(st);
for(i=0;i<5;i++)
{
m=strcmp(st,s[i]);
if(m==0)
flag=1;
}
if(flag==0)
printf("\n it is not a keyword");
else
printf("\n it is a keyword");
getch();
}
OUTPUT
enter the string:return
it is a keyword
enter the string:hello
it is not a keyword
PROGRAM TO FIND WHETHER THE STRING IS CONSTANT OR NOT
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
void main()
{
charstr[10]; int len,a; clrscr();
printf("\n Input a string :");
gets(str); len=strlen(str); a=0; while(a<len)
{
if(isdigit(str[a]))
{
}
else
{
}
}
a++;
printf(" It is not a Constant");
break;
if(a==len)
{
printf(" It is a Constant");
}
getch();
}
OUTPUT
Input a string :23
It is a Constant
Input a string :a_123
It is not a Constant
What if i enter const int? How to check whether it is a keyword or not?
ReplyDeleteIDGAF
ReplyDeletei'm Batting of Aditya Engineering college surampalem with roll no 1_A91A0535 I LOVE TO BAT
ReplyDelete