Facebook
From Cute Kangaroo, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 284
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6. #include <conio.h>
  7. #include<windows.h>
  8.  
  9.  
  10. void printTable(int , int , char**); //wyswietla tablice Matrixa
  11.  
  12.  
  13. void moveRovs (int , int , char**); //opadanie rzedow
  14.  
  15.  
  16. void randomFirstRov (int , int , char**); //losowo wypelnia pierwszy rzad
  17.  
  18.  
  19. void showWord (int , int , char**, char*, int);
  20.  
  21.  
  22. char rnd (); //losuje znak z tablicy ASCII
  23.  
  24.  
  25. void MatrixG(int ,int ,char**);
  26.  
  27.  
  28. int main(int count, char** args)
  29. {
  30. int x, y; //x=ilosc kolumn, y= ilosc wierszy
  31. char** Matrix;
  32.  
  33. printf("Aby wprowadzic tekst wcisnij t\n");
  34. printf("Aby zakonczyc wcisnij q\n");
  35.  
  36.    srand(time(NULL));
  37.  
  38.    if(count==3)
  39.    {
  40.        x = atoi(args[1]);
  41.        y = atoi(args[2]);
  42.    }
  43.         else
  44.         {
  45.             printf("Podaj ilosc kolumn i ilosc wierszy");
  46.             scanf("%d %d", &x, &y);
  47.  
  48.  
  49.         }
  50.  
  51.  
  52. //alokacja pamieci dla Matrixa
  53.  
  54.         Matrix = (char**) malloc(sizeof(Matrix)*y);
  55.  
  56.         for(int i=0; i<y; i++)
  57.         {
  58.             *(Matrix +i) = (char*) (malloc(sizeof(char)*x));
  59.                 for(int j=0; j<x; j++)
  60.                 {
  61.                     *(*(Matrix+i)+j) = rnd();
  62.                 }
  63.         }
  64.  
  65.     system("color 02");
  66.  
  67.  
  68.     MatrixG(x, y, Matrix);
  69.  
  70.  
  71.  
  72.     free(Matrix);
  73.     return 0;
  74. }
  75.  
  76. void printTable(int x, int y, char** Matrix)
  77. {
  78.     for(int i=0; i<y; i++)
  79.     {
  80.         for(int j=0; j<x; j++)
  81.         {
  82.             if(*(*(Matrix+i)+j) == '0')
  83.             {
  84.                 printf("   ");
  85.             }
  86.             else
  87.             {
  88.                 printf("%c  ", *(*(Matrix+i)+j));
  89.             }
  90.         }
  91.         printf("\n");
  92.     }
  93. }
  94.  
  95.  
  96.  
  97. char rnd()
  98. {
  99.     //zakres cyfr w tabeli ASCII
  100.     int min=48;
  101.     int max=57;
  102.  
  103.     return (char) ((rand() % (max-min)) + min);
  104. }
  105.  
  106.  
  107. void moveRovs (int x, int y, char** Matrix)
  108. {
  109.     for(int i=y; i>1; i--)
  110.     {
  111.         memcpy(*(Matrix+i-1),*(Matrix+i-2), sizeof(**Matrix)*x);
  112.     }
  113.         randomFirstRov(x, y, Matrix);
  114. }
  115.  
  116.  
  117. void randomFirstRov (int x , int y , char** Matrix)
  118. {
  119.     for(int i=0; i<x; i++)
  120.         {
  121.             *(*Matrix+i)=rnd();
  122.     }
  123. }
  124.  
  125. void showWord (int x, int y, char** Matrix, char* word, int position)
  126. {
  127.     int k = 0; //zmienna do iterowania liter w s³owie
  128.  
  129.     for(int i=0; i<strlen(word); i++) //wykonuje sie tyle razy ile liter ma s³owo
  130.     {
  131.         for(int j=0; j<x; j++) //wykonuje sie tyle razy liter wierszu
  132.         {
  133.             if(j == position) //je¿eli jesteœmy na podanej pozycji to wstawia literê ze s³owa zamiast losowaæ cyfre
  134.             {
  135.                 *(*Matrix+j)=word[k];
  136.                 k++;
  137.                 continue;
  138.  
  139.             }else
  140.             {
  141.             *(*Matrix+j) = rnd();
  142.             }
  143.         }
  144.  
  145.         for(int j=y; j>1; j--)
  146.         {
  147.              memcpy(*(Matrix+j-1),*(Matrix+j-2), sizeof(**Matrix)*x);
  148.         }
  149.     }
  150.  
  151.     MatrixG(x, y, Matrix);
  152. }
  153.  
  154.  
  155. void MatrixG(int x, int y, char** Matrix)
  156. {
  157.     char letter;
  158.     while(1 && ((letter!='t') && (letter!='q'))) // 1 odpowiada za ciągłe powtarzanie pętli, kolejny warunek sprawza czy nie został wciscniety klawisz q bądz t
  159.     {
  160.         system("cls");
  161.  
  162.         printTable(x, y, Matrix);
  163.  
  164.         moveRovs(x, y, Matrix);
  165.  
  166.         if(kbhit()) //sprawdza czy został nacieśniety klawisz
  167.         {
  168.         letter=getch(); //pobiera znak z klawiatury
  169.  
  170.         }
  171.  
  172.         //system("timeout 1"); //zmiana tablicy co 1 sekunde
  173.         //sleep(1);
  174.  
  175.         system("ping 127.0.0.1 -n 1 w 500 > nul"); //system pinguje swój lokalny adres jednym pakietem poczym odczekuje 500 mili sekund co daje efekt animacji
  176.     }
  177.  
  178.     if(letter=='q')
  179.     {
  180.         exit(0);
  181.     }
  182.  
  183.     char word[25]; //maksymalna liczba liter w słowie
  184.     int position;
  185.  
  186.     printf("Podaj slowo");
  187.     scanf("%s", word);
  188.  
  189.     printf("podaj pozycje", &position);
  190.     scanf("%d", &position);
  191.  
  192.     showWord(x, y, Matrix, word, position);
  193. }
  194.