forked from Anurag2622002/Codefornewccoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidIdentifier.c
More file actions
44 lines (40 loc) · 739 Bytes
/
validIdentifier.c
File metadata and controls
44 lines (40 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char s[50];
int n,i,flag=1;
char keywords[][10] = {"if","else","for","do","while"};
int ksize = sizeof(keywords)/10;
puts("Enter the identifier:");
gets(s);
for(i=0;i<ksize;i++)
{
if(strcmp(s,keywords[i])==0)
{
flag = 0;
break;
}
}
n = strlen(s);
if(isdigit(s[0]) && flag)
flag = 0;
else if(flag)
{
for(i=0;i<n;i++)
{
if(s[i]=='_' || isalnum(s[i]));
else
{
flag=0;
break;
}
}
}
if(flag)
puts("identifier is valid");
else
puts("identifier is not valid");
return 0;
}