FaltuTech.Club : Fane of Advanced Logical Thriving Utopian Technical Club

Keyword Validation in C

Check the validity of all keywords of c language. This a part of compilation work.



#include 
#include 
#include 
  int isValid(char arr[]);

void main() {

  char string[20], c = 'y';
  int i, valid = 0;
  clrscr();
  do {
    string[0] = '\0';
    printf("Enter Your Keyword : ");
    gets(string);
    valid = isValid(string);
    if (valid == 0) {
      printf("The given keyword is not a valid keyword");
    } else {
      printf("The given keyword is a valid keyword");
    }
    printf("\nDo you want to check more (y|Y) : ");
    scanf("%c", & c);
    fflush(stdin);
  }
  while (c == 'y' || c == 'Y');

  getch();
}

int isValid(char arr[]) {
    int start = 0;
    char first = arr[start];
    // check keywords starting with a

    if (first == 'a') {
      start++;
      if (arr[start] == 'u') {
        start++;
        if (arr[start] == 't') {
          start++;
          if (arr[start] == 'o') {
            start++;
            if (arr[start] == '\0') {
              return 1;
            } else
              return 0;
          } else {
            return 0;
          }
        } else
          return 0;
      } else {
        return 0;
      }
    }

    // check keywords starting with b
    else if (first == 'b') {
      start++;
      if (arr[start] == 'r') {
        start++;
        if (arr[start] == 'e') {
          start++;
          if (arr[start] == 'a') {
            start++;
            if (arr[start] == 'k') {
              start++;
              if (arr[start] == '\0')
                return 1;
              else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else
        return 0;
    }

    // check keywords starting with c
    else if (first == 'c') {
      start++;
      if (arr[start] == 'a') {
        start++;
        if (arr[start] == 's') {
          start++;
          if (arr[start] == 'e') {
            start++;
            if (arr[start] == '\0')
              return 1;
            else
              return 0;
          } else {
            return 0;
          }

        } else {
          return 0;
        }
      } else if (arr[start] == 'h') {
        start++;
        if (arr[start] == 'a') {
          start++;
          if (arr[start] == 'r') {
            start++;
            if (arr[start] == '\0')
              return 1;
            else
              return 0;
          } else {
            return 0;
          }

        } else {
          return 0;
        }
      } else if (arr[start] == 'o') {
        start++;
        if (arr[start] == 'n') {
          start++;
          if (arr[start] == 't') {
            start++;
            if (arr[start] == 'i') {
              start++;
              if (arr[start] == 'n') {
                start++;
                if (arr[start] == 'u') {
                  start++;
                  if (arr[start] == 'e') {
                    start++;
                    if (arr[start] == '\0')
                      return 1;
                    else
                      return 0;
                  } else {
                    return 0;
                  }
                } else {
                  return 0;
                }
              } else {
                return 0;
              }
            } else {
              return 0;
            }
          } else if (arr[start] == 's') {
            start++;
            if (arr[start] == 't') {
              start++;
              if (arr[start] == '\0')
                return 1;
              else
                return 0;
            } else
              return 0;
          } else {
            return 0;
          }

        } else {
          return 0;
        }
      }
    } // check keywords starting with d
    else if (first == 'd') {
      start++;

      if (arr[start] == 'o') {
        start++;
        if (arr[start] == '\0') {
          return 1;
        } else if (arr[start] == 'u') {
          start++;
          if (arr[start] == 'b') {
            start++;
            if (arr[start] == 'l') {
              start++;
              if (arr[start] == 'e') {
                start++;
                if (arr[start] == '\0')
                  return 1;
                else
                  return 0;
              } else
                return 0;
            } else {
              return 0;
            }
          } else {
            return 0;
          }
        } else {
          return 0;
        }
      } else if (arr[start] == 'e') {
        start++;
        if (arr[start] == 'f') {
          start++;
          if (arr[start] == 'a') {
            start++;
            if (arr[start] == 'u') {
              start++;
              if (arr[start] == 'l') {
                start++;
                if (arr[start] == 't') {
                  start++;
                  if (arr[start] == '\0')
                    return 1;
                  else
                    return 0;
                }
                return 0;
              } else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else {
        return 0;
      }

    } // check keywords starting with e
    else if (first == 'e') {
      start++;
      if (arr[start] == 'x') {
        start++;
        if (arr[start] == 'i') {
          start++;
          if (arr[start] == 't') {
            start++;
            if (arr[start] == '\0')
              return 1;
            else
              return 0;
          } else {
            return 0;
          }
        } else if (arr[start] == 't') {
          start++;
          if (arr[start] == 'e') {
            start++;
            if (arr[start] == 'r') {
              start++;
              if (arr[start] == 'n') {
                start++;
                if (arr[start] == '\0')
                  return 1;
                else
                  return 0;
              } else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else {
          return 0;
        }
      } else if (arr[start] == 'l') {
        start++;
        if (arr[start] == 's') {
          start++;
          if (arr[start] == 'e') {
            start++;
            if (arr[start] == '\0')
              return 1;
            else
              return 0;
          } else {
            return 0;
          }
        } else {
          return 0;
        }
      } else if (arr[start] == 'n') {
        start++;
        if (arr[start] == 'u') {
          start++;
          if (arr[start] == 'm') {
            start++;
            if (arr[start] == '\0')
              return 1;
            else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else {
        return 0;
      }

    } // check keywords starting with f
    else if (first == 'f') {
      start++;
      if (arr[start] == 'o') {
        start++;
        if (arr[start] == 'r') {
          start++;
          if (arr[start] == '\0')
            return 1;
          else
            return 0;
        } else {
          return 0;
        }
      } else if (arr[start] == 'l') {
        start++;
        if (arr[start] == 'o') {
          start++;
          if (arr[start] == 'a') {
            start++;
            if (arr[start] == 't') {
              start++;
              if (arr[start] == '\0')
                return 1;
              else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else {
        return 0;
      }

    } // check keywords starting with g
    else if (first == 'g') {
      start++;
      if (arr[start] == 'o') {
        start++;
        if (arr[start] == 't') {
          start++;
          if (arr[start] == 'o') {
            start++;
            if (arr[start] == '\0')
              return 1;
            else
              return 0;
          } else {
            return 0;
          }
        } else {
          return 0;
        }
      } else {
        return 0;
      }

    }

    // check keywords starting with i
    else if (first == 'i') {
      start++;
      if (arr[start] == 'n') {
        start++;
        if (arr[start] == 't') {
          start++;
          if (arr[start] == '\0')
            return 1;
          else
            return 0;
        } else
          return 0;
      } else if (arr[start] == 'f') {
        start++;
        if (arr[start] == '\0')
          return 1;
        else
          return 0;
      } else
        return 0;
    }

    // check keywords starting with L (l)
    else if (first == 'l') {
      start++;
      if (arr[start] == 'o') {
        start++;
        if (arr[start] == 'n') {
          start++;
          if (arr[start] == 'g') {
            start++;
            if (arr[start] == '\0')
              return 1;
            else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else
        return 0;
    }

    // check keywords starting with r
    else if (first == 'r') {
      start++;
      if (arr[start] == 'e') {
        start++;
        if (arr[start] == 'g') {
          start++;
          if (arr[start] == 'i') {
            start++;
            if (arr[start] == 's') {
              start++;
              if (arr[start] == 't') {
                start++;
                if (arr[start] == 'e') {
                  start++;
                  if (arr[start] == 'r') {
                    start++;
                    if (arr[start] == '\0')
                      return 1;
                    else
                      return 0;
                  } else
                    return 0;
                } else
                  return 0;
              } else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else if (arr[start] == 't') {
          start++;
          if (arr[start] == 'u') {
            start++;
            if (arr[start] == 'r') {
              start++;
              if (arr[start] == 'n') {
                start++;
                if (arr[start] == '\0')
                  return 1;
                else
                  return 0;
              } else
                return 0;
            } else
              return 0;
          }
          return 0;
        } else
          return 0;
      } else
        return 0;
    }

    // check keywords starting with s
    else if (first == 's') {
      start++;
      if (arr[start] == 'h') {
        start++;
        if (arr[start] == 'o') {
          start++;
          if (arr[start] == 'r') {
            start++;
            if (arr[start] == 't') {
              start++;
              if (arr[start] == '\0')
                return 1;
              else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else if (arr[start] == 'i') {
        start++;
        if (arr[start] == 'z') {
          start++;
          if (arr[start] == 'e') {
            start++;
            if (arr[start] == 'o') {
              start++;
              if (arr[start] == 'f') {
                start++;
                if (arr[start] == '\0')
                  return 1;
                else
                  return 0;
              } else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else if (arr[start] == 'g') {
          start++;
          if (arr[start] == 'n') {
            start++;
            if (arr[start] == 'e') {
              start++;
              if (arr[start] == 'd') {
                start++;
                if (arr[start] == '\0')
                  return 1;
                else
                  return 0;
              } else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else if (arr[start] == 't') {
        start++;
        if (arr[start] == 'r') {
          start++;
          if (arr[start] == 'u') {
            start++;
            if (arr[start] == 'c') {
              start++;
              if (arr[start] == 't') {
                start++;
                if (arr[start] == '\0')
                  return 1;
                else
                  return 0;
              } else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else if (arr[start] == 'a') {
          start++;
          if (arr[start] == 't') {
            start++;
            if (arr[start] == 'i') {
              start++;
              if (arr[start] == 'c') {
                start++;
                if (arr[start] == '\0')
                  return 1;
                else
                  return 0;
              } else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else if (arr[start] == 'w') {
        start++;
        if (arr[start] == 'i') {
          start++;
          if (arr[start] == 't') {
            start++;
            if (arr[start] == 'c') {
              start++;
              if (arr[start] == 'h') {
                start++;
                if (arr[start] == '\0')
                  return 1;
                else
                  return 0;
              } else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else
        return 0;
    }
    // check keywords starting with t
    else if (first == 't') {
      start++;
      if (arr[start] == 'y') {
        start++;
        if (arr[start] == 'p') {
          start++;
          if (arr[start] == 'e') {
            start++;
            if (arr[start] == 'd') {
              start++;
              if (arr[start] == 'e') {
                start++;
                if (arr[start] == 'f') {
                  start++;
                  if (arr[start] == '\0')
                    return 1;
                  else
                    return 0;
                } else
                  return 0;
              } else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else
        return 0;
    }
    // check keywords starting with u
    else if (first == 'u') {
      start++;
      if (arr[start] == 'n') {
        start++;
        if (arr[start] == 's') {
          start++;
          if (arr[start] == 'i') {
            start++;
            if (arr[start] == 'g') {
              start++;
              if (arr[start] == 'n') {
                start++;
                if (arr[start] == 'e') {
                  start++;
                  if (arr[start] == 'd') {
                    start++;
                    if (arr[start] == '\0')
                      return 1;
                    else
                      return 0;
                  } else
                    return 0;
                } else
                  return 0;
              } else
                return 0;
            } else
              return 0;

          } else
            return 0;
        } else if (arr[start] == 'i') {
          start++;
          if (arr[start] == 'o') {
            start++;
            if (arr[start] == 'n') {
              start++;
              if (arr[start] == '\0')
                return 1;
              else
                return 0;

            } else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else
        return 0;
    }

    // check keywords starting with v
    else if (first == 'v') {
      start++;
      if (arr[start] == 'o') {
        start++;
        if (arr[start] == 'l') {
          start++;
          if (arr[start] == 'a') {
            start++;
            if (arr[start] == 't') {
              start++;
              if (arr[start] == 'i') {
                start++;
                if (arr[start] == 'l') {
                  start++;
                  if (arr[start] == 'e') {
                    start++;
                    if (arr[start] == '\0')
                      return 1;
                    else
                      return 0;
                  } else
                    return 0;
                } else
                  return 0;
              } else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else if (arr[start] == 'i') {
          start++;
          if (arr[start] == 'd') {
            start++;
            if (arr[start] == '\0')
              return 1;
            else
              return 0;
          } else
            return 0;

        } else
          return 0;

      } else
        return 0;
    }

    // check keywords starting with w
    if (arr[start] == 'w') {
      start++;
      if (arr[start] == 'h') {
        start++;
        if (arr[start] == 'i') {
          start++;
          if (arr[start] == 'l') {
            start++;
            if (arr[start] == 'e') {
              start++;
              if (arr[start] == '\0')
                return 1;
              else
                return 0;
            } else
              return 0;
          } else
            return 0;
        } else
          return 0;
      } else
        return 0;
    }

    // default if nothing above matches
    else {
      return 0;
    }

  } // function closed