Untitled
unknown
c_cpp
2 years ago
1.3 kB
3
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 ) { int is_digit = 0; for (int i = 0; i < strlen(token); i++) { if (!(token[i] >= '0' && token[i] <= '9')) { is_digit = 0; break; } is_digit = 1; } if (is_digit == 1) { printf("%s\tnumber\n", token); } else 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 (token[0] >= '0' && token[0] <= '9') { printf("%s\tunidentifier\n", token); } else { printf("%s\tidentifier\n", token); } token = strtok(NULL, s); } return(0); }