-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeywords.c
51 lines (50 loc) · 1.27 KB
/
keywords.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
#include<stdio.h>
#include<string.h>
int main() {
FILE *f;
char fname[100],temp[20];
char keyw[20][10] = {"if","break","else","switch","typedef","register","enum","case","extern","return","union","const","continue","for","default","int","float","do","while","sizeof"};
printf("\nEnter the absolute path of C file: ");
char op1[] = {'+','-','=','!','<','>','&','|','+','-','*','/','%','&','^','|'};
char op2[] = {'+','-','=','=','=','=','&','|','=','=','=','=','=','=','=','='};
scanf("%s",&fname);
f = fopen(fname,"r");
char cpro[1000];
fread(cpro,1000,sizeof(char),f);
int n = strlen(cpro);
int i = 0;
int j,k;
int top = 0;
while(i<n) {
if(cpro[i] != ' ' && cpro[i] != '(' && cpro[i] != ';' && cpro[i] != '\n' && cpro[i] != '\0') {
if(i<n-1) {
for(k=0;k<16;k++) {
if(cpro[i]==op1[k]) {
if(cpro[i+1]==op2[k]) {
printf("\nOperator detected: %c%c\n",cpro[i],cpro[i+1]);
i++;
break;
} else {
printf("\nOperator detected: %c\n",cpro[i]);
break;
}
}
}
}
temp[top] = cpro[i];
top++;
} else {
j = 0;
while(j<20) {
if(strcmp(keyw[j],temp)==0) {
printf("\nKeyword found: %s\n",temp);
break;
}
j++;
}
memset(temp,'\0',sizeof(temp));
top = 0;
}
i++;
}
}