Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.1 kB
2
Indexable
Never
#include <string.h>
#include <stdio.h>

int is_digits(char *token) {
    for (int i = 0; i < strlen(token); i++) {
        if (!(token[i] >= '0' && token[i] <= '9'))
            return 0;
    }

    return 1;
}

int main () {
   char str[80];
   const char s[2] = " ";
   char *token;
   
   printf("please enter sentense :");
   gets(str);
   token = strtok(str, s);
   while( token != NULL ) {
	if (strcmp(token, "add")==0){
		printf("%s\treserved\n",token);
	}else if (strcmp(token, "sub")==0){
		printf("%s\treserved\n",token);
	}else if (strcmp(token, "mul")==0){
		printf("%s\treserved\n",token);
	}else if (strcmp(token, "div")==0){
		printf("%s\treserved\n",token);
	}else if (strcmp(token, "display")==0){
		printf("%s\treserved\n",token);
	}else if (strcmp(token, "read")==0){
		printf("%s\treserved\n",token);			
    } else if (is_digits(token)) {
        printf("%s\tnumber\n", token);
    } else if (token[0] >= '0' && token[0] <= '9') {
        printf("%s\tunidentifier\n", token);
    } else {
        printf("%s\tidentifier\n", token);
    }
	token = strtok(NULL, s);
   }
   
   return(0);
}