#include #include #include /** @author Ivan Cukic */ #define LETTER_COUNT 'z' - 'a' + 1 #define SPC_COUNT 21 int tag_In = 0; int spc_In = 0; char tag_Text[30] = "\0"; char spc_Text[30] = "&\0"; int tag_Index = 0; int spc_Index = 1; int c_normal_count[300]; int c_special_count[SPC_COUNT]; char c_special_chars[SPC_COUNT][10]={"&Sx;", "&sx;", "&Cy;", "&cy;", "&Cx;", "&cx;", "&Dx;", "&dx;", "&Zx;", "&zx;", "&Lx;", "&lx;", "&Nx;", "&nx;", "&Dz;", "&dz;", "&", "<", ">"}; int c_seg = 0; int c_p = 0; int c_words = 0; struct stack { struct stack *child; char tag_Text[20]; } *s_root, *s_new; int getSPC() { for (int i = 0; i < SPC_COUNT; i++) { if (strcmp(c_special_chars[i], spc_Text) == 0) return i; } printf ("\n B - %s", spc_Text); return SPC_COUNT + 1; } main(int argc, char *argv[]) { char c = getchar(); s_root = 0; while (c != EOF) { //printf ("\nProcessing %c ...", c); if (c == '&') spc_In = 1; else if (c == '<') tag_In = 1; else { //printf (" - Tag : %i %s \t || Spc: %i %s \t", tag_In, tag_Text, spc_In, spc_Text); //printf (" - Seg : %i || P : %i", c_seg, c_p); if (tag_In) { tag_Text[tag_Index++] = c; tag_Text[tag_Index] = '\0'; } else if (spc_In) { spc_Text[spc_Index++] = c; spc_Text[spc_Index] = '\0'; } if ((tag_In) && (c == '>')) { tag_In = 0; tag_Index = 0; if (tag_Text[0] != '/') { s_new = (struct stack *) malloc(sizeof(struct stack)); strcpy(s_new->tag_Text, tag_Text); s_new->child = s_root; s_root = s_new; } else if (s_root != NULL) { while (strcmp(s_root->tag_Text, tag_Text + 1)) { printf ("\n --- Error :: Tag not closed :: <%s", s_root->tag_Text); s_new = s_root; s_root = s_root->child; free(s_new); } if (s_root) { if (strcmp(s_root->tag_Text, "seg>") == 0) c_seg++; if (strcmp(s_root->tag_Text, "p>") == 0) c_p++; s_new = s_root; s_root = s_root->child; free(s_new); } } } else if ((spc_In) && (c == ';')) { spc_In = 0; spc_Index = 1; c_special_count[getSPC()]++; } else if ((!spc_In) && (!tag_In)) { c_normal_count[c]++; if (c == ' ') c_words ++; } } c = getchar(); } printf ("\n\n-------------------------------------------------------------------------"); printf ("\n - : %i", c_seg); printf ("\n -

: %i", c_p); printf ("\n - words : %i", c_words); printf ("\n-------------------------------------------------------------------------"); for (int j = 33; j < 127; j++) { printf ("\n - (char)%i - '%c' - %i", j, j, c_normal_count[j]); } for (int j = 0; j < SPC_COUNT; j++) { printf ("\n - %s - %i", c_special_chars[j], c_special_count[j]); } return 0; }