Advertisement
tsounakis

yes

Apr 16th, 2020
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define N 30
  5. #define M 100
  6.  
  7. char DEVELOPMENT[] = "";
  8.  
  9. char getchoice();
  10. void read(char a[M][N], char endword[], int *plength);
  11. void loaddict();
  12. void correct();
  13. void save();
  14. void stats(char a[M][N], int length);
  15. void legend();
  16.  
  17. int main() {
  18.     char choice, text[M][N], endword[] = "end", dict[M][N];
  19.     int length = 0;
  20.     int *plength;
  21.     plength = &length;
  22.     if (strcmp(DEVELOPMENT, "ON") == 0)
  23.     {
  24.         printf("DEVELOPMENT MODE[ON]\n");
  25.     }
  26.     legend();
  27.     while(1)
  28.     {      
  29.         printf("CHOOSE AN ACTION: ");
  30.         choice = getchoice();
  31.         switch (choice)
  32.         {
  33.             case 'r':
  34.                 read(text, endword, plength);
  35.                 break;
  36.             case 'd':
  37.                 loaddict(dict, endword);
  38.                 break;
  39.             case 'c':
  40.                 correct();
  41.                 break;
  42.             case 's':
  43.                 save();
  44.                 break;
  45.             case 'S':
  46.                 stats(text, length);
  47.                 break;
  48.             case 'l':
  49.                 legend();
  50.                 break;
  51.             case 'e':
  52.                 return 0;
  53.                 break;
  54.             default:
  55.                 printf("\n*Wrong input*\n");
  56.                 break;
  57.         }
  58.         putchar('\n');
  59.     }
  60. }
  61. char getchoice()
  62. {
  63.     char choice;
  64.     scanf(" %c", &choice);
  65.     return choice;
  66. }
  67.  
  68. void read(char a[M][N], char endword[], int *plength)
  69. {
  70.     char test[N];
  71.     int i;
  72.     i=0;
  73.     printf("(READ TEXT MODE[ON]):~ *INITIATING READ TEXT MODE*\n");
  74.     while(1)
  75.     {
  76.         while (1)
  77.         {  
  78.             printf("Type: ");
  79.             scanf(" %s", test);
  80.             if (strcpy(DEVELOPMENT, "ON") == 0)
  81.             {
  82.                 printf("%d\n", strlen(test));
  83.             }
  84.             if (strlen(test) >= N)
  85.             {
  86.                 printf("\nError: possible buffer overflow due to the length of the typed word. Please retype.\n");
  87.             }
  88.             else
  89.             {
  90.                 break;
  91.             }
  92.         }
  93.         if (strcmp(test, endword) == 0)
  94.         {
  95.             break;
  96.         }
  97.         strcpy(a[i], test);
  98.         i++;
  99.     }
  100.     *plength = i;
  101.     printf("(READ TEXT MODE[OFF]...):~ \n");
  102.     return;
  103. }
  104.  
  105. void loaddict()
  106. {
  107.     printf("\nDummy function.\n");
  108.     return;
  109. }
  110.  
  111. void correct()
  112. {
  113.     printf("\nText corrected.\n\n");
  114.     return;
  115. }
  116.  
  117. void save()
  118. {
  119.     printf("\nText saved.\n\n");
  120.     return;
  121. }
  122.  
  123. void stats(char a[M][N], int length)
  124. {
  125.     char choice, da[M][N], old[M][N];
  126.     int lengthWords, lengthChars = 0, i, j, stop = 0, diff = 0, occ, occA[M] = {0}, k;
  127.     for (i=0; i<length; i++)
  128.     {
  129.         strcpy(old[i], a[i]);
  130.         strupr(a[i]);
  131.     }
  132.     printf("(STATS MODE[ON]):~ *INITIATING STATS MODE*\n");
  133.     if (strlen(a[0]) == 0)
  134.     {
  135.         printf("NON READABLE TEXT.\n");
  136.         return;
  137.     }
  138.     for (i=0; i < length; i++)
  139.     {
  140.         for (j=0; a[i][j] != '\0'; j++)
  141.         {
  142.             lengthChars++;
  143.         }
  144.     }
  145.     lengthWords = i;
  146.     for (i=0; i < length; i++)
  147.     {
  148.         occ = 1;
  149.         for (j=i; j<length;j++)
  150.         {
  151.             if (strcmp(a[i], "*0*0*0*") != 0)
  152.             {
  153.                 if (strcmp(a[i], a[j]) == 0 && i != j)
  154.                 {
  155.                     occ++;
  156.                     strcpy(a[j], "*0*0*0*");
  157.                 }
  158.                 if (j == length - 1)
  159.                 {
  160.                     strcpy(da[diff], old[i]);
  161.                     occA[diff] = occ;
  162.                     diff++;
  163.                 }
  164.             }  
  165.         }
  166.     }
  167.     while (stop == 0)
  168.     {
  169.         printf("\nCHOOSE [a, b or c]:");
  170.         scanf(" %c", &choice);
  171.         switch(choice){
  172.             case 'a':
  173.                 printf("The text is composed of %d words and %d characters (%d including the spaces).\n", lengthWords, lengthChars, lengthChars + lengthWords - 1);
  174.                 break;
  175.             case 'b':
  176.                 printf("The text is composed of %d different words.\n", diff);
  177.                 break;
  178.             case 'c':
  179.                 printf("Word:\tOccurence:\t\n");
  180.                 for (i=0; i<length; i++)
  181.                 {
  182.                     for (j=0; j<length; j++)
  183.                     {
  184.                         if (i==occA[j])
  185.                         {
  186.                             printf("%s\t:\t", da[j]);
  187.                             for (k=0; k<occA[j];k++)
  188.                             {
  189.                                 printf("*");
  190.                             }
  191.                             putchar('\n');
  192.                         }
  193.                     }
  194.                 }
  195.                 break;
  196.             case 'e':
  197.                 stop = 1;
  198.             default:
  199.                 break;
  200.         }
  201.     }  
  202.     printf("(STATS MODE[OFF]):~ ...\n");
  203.     return;
  204. }
  205.  
  206. void legend()
  207. {
  208.     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");
  209.     return;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement