Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 30
- #define M 100
- char DEVELOPMENT[] = "OFF";
- void histogram(char a[M][N], int lengthofwords[], int length);
- char getchoice();
- void cleanString(char []);
- void read(char a[M][N], int*, int*, FILE*);
- void loaddict();
- void correct();
- void save();
- void stats(char a[M][N], int, int);
- void legend();
- int main() {
- FILE* input;
- char choice, text[M][N];
- int length = 0, spaces;
- int* ptr_length;
- int* ptr_spaces;
- input = NULL;
- ptr_spaces = &spaces;
- ptr_length = &length;
- legend();
- while(1)
- {
- printf("CHOOSE AN ACTION: ");
- choice = getchoice();
- switch (choice)
- {
- case 'r':
- read(text, ptr_length, ptr_spaces, input);
- break;
- case 'd':
- loaddict();
- break;
- case 'c':
- correct();
- break;
- case 's':
- save();
- break;
- case 'S':
- stats(text, length, spaces);
- break;
- case 'l':
- legend();
- break;
- case 'e':
- return 0;
- break;
- default:
- printf("\n*Wrong input*\n");
- break;
- }
- putchar('\n');
- }
- }
- char getchoice()
- {
- char choice;
- scanf(" %c", &choice);
- return choice;
- }
- void read(char a[M][N], int* ptr_length, int* ptr_spaces, FILE* input)
- {
- char ch;
- int i, length, spaces = 0;
- *ptr_spaces = 0;
- input = fopen("input.txt", "r+");
- printf("(READ TEXT MODE[ON]):~ INITIATING READ TEXT MODE\n");
- /*Search for spaces*/
- while ((ch = fgetc(input)) != EOF)
- {
- if (ch == ' ')
- {
- spaces++;
- }
- }
- *ptr_spaces = spaces;
- fseek(input, 0, SEEK_SET);
- /**/
- for (i=0; feof(input) == 0; i++)
- {
- fscanf(input, "%s", a[i]);
- if (ferror(input) != 0)
- {
- printf("ERROR. EXITING READ MODE");
- return;
- }
- }
- length = i;
- if (strcmp(DEVELOPMENT, "ON") == 0)
- {
- for (i=0; i<length; i++)
- {
- printf("%s\n", a[i]);
- }
- }
- printf("(READ TEXT MODE[OFF]...):~ SUCCESSFULLY READ THE TEXT\n");
- *ptr_length = length;
- fclose(input);
- return;
- }
- void loaddict()
- {
- printf("\nDummy function.\n");
- return;
- }
- void correct()
- {
- printf("\nText corrected DUMMY FUNCTION.\n\n");
- return;
- }
- void save()
- {
- printf("\nText saved DUMMY FUNCTION.\n\n");
- return;
- }
- void cleanString(char str[N])
- {
- int i, j;
- for(i=0; str[i]!='\0'; ++i)
- {
- while (!((str[i]>='a'&&str[i]<='z') || ((str[i]>='A' && str[i]<='Z') || str[i]=='\0') || (str[i]>='0' && str[i]<='9') || (str[i])=='\''))
- {
- for(j=i;str[j]!='\0';++j)
- {
- str[j]=str[j+1];
- }
- str[j]='\0';
- }
- }
- return;
- }
- void histogram(char a[M][N], int lengthofwords[], int length)
- {
- int i, j, lengthWord;
- for (i=0;i<N;i++)
- {
- j = 0;
- while (j!=length)
- {
- lengthWord = strlen(a[j]);
- if (lengthWord == i)
- {
- lengthofwords[i]++;
- }
- j++;
- }
- }
- return;
- }
- void stats(char a[M][N], int length, int spaces)
- {
- char choice, old[M][N];
- int lengthWords, lengthChars = 0, i, j, stop = 0, diff = 0, lengthofwords[N] = {0};
- for (i=0; i<length; i++)
- {
- cleanString(a[i]);
- }
- for (i=0; i<length; i++)
- {
- strcpy(old[i], a[i]);
- strupr(a[i]);
- }
- printf("(STATS MODE[ON]):~ *INITIATING STATS MODE*\n");
- if (strlen(a[0]) == 0)
- {
- printf("NON READABLE TEXT.\n");
- return;
- }
- for (i=0; i < length; i++)
- {
- for (j=0; old[i][j] != '\0'; j++)
- {
- lengthChars++;
- }
- }
- lengthWords = i;
- histogram(a, lengthofwords, length);
- for (i=0; i < length; i++)
- {
- for (j=i; j<length;j++)
- {
- if (strcmp(a[i], "*0*0*0*") != 0)
- {
- if (strcmp(a[i], a[j]) == 0 && i != j)
- {
- strcpy(a[j], "*0*0*0*");
- }
- if (j == length - 1)
- {
- diff++;
- }
- }
- }
- }
- while (stop == 0)
- {
- printf("\n(STATS MODE[ON]):~ CHOOSE [a, b or c]:");
- scanf(" %c", &choice);
- switch(choice){
- case 'a':
- printf("(STATS MODE[ON]):~ The text is composed of %d words and %d characters (%d including the spaces).\n", lengthWords, lengthChars, spaces + lengthChars);
- break;
- case 'b':
- printf("(STATS MODE[ON]):~ The text is composed of %d different words.\n", diff);
- break;
- case 'c':/* USEFUL GARBAGE
- printf("Word:\tOccurence:\t\n");
- for (i=0; i<length; i++)
- {
- for (j=0; j<length; j++)
- {
- if (i==occA[j] && occA[j] != 0)
- {
- printf("%s\t:\t", da[j]);
- for (k=0; k<occA[j];k++)
- {
- printf("*");
- }
- putchar('\n');
- }
- }
- }*/
- printf("(STATS MODE[ON]):~ ");
- printf("\n# of chars\t# of words:");
- printf("\nin a word:\n\n");
- for (i=1;i<N;i++)
- {
- printf("%d\t\t", i);
- for (j=0; j<lengthofwords[i];j++)
- {
- putchar('*');
- }
- putchar('\n');
- }
- break;
- case 'e':
- stop = 1;
- default:
- break;
- }
- }
- printf("(STATS MODE[OFF]):~ ...\n");
- return;
- }
- void legend()
- {
- printf("LEGEND:\n[r:\tInsert text]\n[d:\tLoad dictionary]\n[c:\tCorrect the loaded text]\n[S:\tStatistics]\n[s:\tSave text]\n[l:\tShow legend]\n[e:\tEscape]\n");
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement