-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fig.5.9.c
69 lines (55 loc) · 1.57 KB
/
Fig.5.9.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
void main(){
char input[100],c;
int i;
char valid[]="VALID TOKEN!";
char invalid[]="INVALID TOKEN!";
printf("Please enter the symbol: ");
gets(input);
c=input[0];
i=1;
if(isalpha(c))
if(i==strlen(input))
printf("\n%s\n",invalid);
else{
c=input[i++];
while(isalnum(c) && i<strlen(input))
c=input[i++];
if(i==strlen(input))
if(isalnum(c) || c=='.')
printf("\n%s\n",valid);
else
printf("\n%s\n",invalid);
else
printf("\n%s\n",invalid);
}
else if(isdigit(c)){
while(i<strlen(input) && isdigit(input[i++]));
if(i==strlen(input))
printf("\n%s\n",valid);
else
printf("\n%s\n",invalid);
}
else if(c==';' || c==',' || c=='+' || c=='-' || c=='*' || c==')' || c=='(' ){
if(i==strlen(input))
printf("\n%s\n",valid);
else
printf("\n%s\n",invalid);
}
else if(c==':'){
if(i==strlen(input))
printf("\n%s\n",valid);
else{
c=input[i++];
if(c=='=' && i==strlen(input))
printf("\n%s\n",valid);
else
printf("\n%s\n",invalid);
}
}
else
printf("\n%s\n",invalid);
}