delimeters.c 1010 B

123456789101112131415161718192021222324252627282930313233
  1. #include <stdio.h>
  2. int main (int argc, char **argv) {
  3. if (argc < 2) {
  4. printf ("Usage:\n");
  5. printf ("\t~> %s [string]\n", argv[0]);
  6. printf ("where [string] is a string to check.\n");
  7. } else {
  8. char *ptr = argv[1];
  9. char *tmp = ptr;
  10. while (*ptr) {
  11. if (*ptr == '(' || *ptr == '[' || *ptr == '{') {
  12. tmp = ptr;
  13. while (*tmp) {
  14. if (*tmp == ')' || *tmp == ']' || *tmp == '}') {
  15. if ((*ptr == '(' && *tmp == ')') ||
  16. (*ptr == '[' && *tmp == ']') ||
  17. (*ptr == '{' && *tmp == '}')) {
  18. break;
  19. } else {
  20. printf ("Not valid.\n");
  21. return 0;
  22. }
  23. }
  24. tmp++;
  25. }
  26. }
  27. ptr++;
  28. }
  29. }
  30. printf ("Valid.\n");
  31. return 0;
  32. }