Facebook
From Little Stork, 6 Years ago, written in Plain Text.
This paste is a reply to Untitled from Bistre Bongo - view diff
Embed
Download Paste or View Raw
Hits: 409
  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.  
  8. void printTable(int , int , char**); //wyswietla tablice Matrixa
  9.  
  10.  
  11. void moveRovs (int , int , char**); //opadanie rzedow
  12.  
  13.  
  14. void randomFirstRov (int , int , char**); //losowo wypelnia pierwszy rzad
  15.  
  16.  
  17. void showWord (int , int , char**, char*, int);
  18.  
  19.  
  20. char rnd (); //losuje znak z tablicy ASCII
  21.  
  22.  
  23. void MatrixG(int ,int ,char**);
  24.  
  25.  
  26. int main(int count, char** args)
  27. {
  28. int x, y; //x=ilosc kolumn, y= ilosc wierszy
  29. char** Matrix;
  30.  
  31.    srand(time(NULL));
  32.  
  33.    if(count==3)
  34.    {
  35.        x = atoi(args[1]);
  36.        y = atoi(args[2]);
  37.    }
  38.         else
  39.         {
  40.             printf("Podaj ilosc kolumn i ilosc wierszy");
  41.             scanf("%d %d", &x, &y);
  42.  
  43.  
  44.         }
  45.  
  46.  
  47. //alokacja pamieci dla Matrixa
  48.  
  49.         Matrix = (char**) malloc(sizeof(Matrix)*y);
  50.  
  51.         for(int i=0; i<y; i++)
  52.         {
  53.             *(Matrix +i) = (char*) (malloc(sizeof(char)*x));
  54.                 for(int j=0; j<x; j++)
  55.                 {
  56.                     *(*(Matrix+i)+j) = rnd();
  57.                 }
  58.         }
  59.  
  60.     system("color 02");
  61.  
  62.  
  63.     MatrixG(x, y, Matrix);
  64.  
  65.  
  66.  
  67.     free(Matrix);
  68.     return 0;
  69. }
  70.  
  71. void printTable(int x, int y, char** Matrix)
  72. {
  73.     for(int i=0; i<y; i++)
  74.     {
  75.         for(int j=0; j<x; j++)
  76.         {
  77.             if(*(*(Matrix+i)+j) == '0')
  78.             {
  79.                 printf("   ");
  80.             }
  81.             else
  82.             {
  83.                 printf("%c  ", *(*(Matrix+i)+j));
  84.             }
  85.         }
  86.         printf("\n");
  87.     }
  88. }
  89.  
  90.  
  91.  
  92. char rnd()
  93. {
  94.     //zakres cyfr w tabeli ASCII
  95.     int min=48;
  96.     int max=57;
  97.  
  98.     return (char) ((rand() % (max-min)) + min);
  99. }
  100.  
  101.  
  102. void moveRovs (int x, int y, char** Matrix)
  103. {
  104.     for(int i=y; i>1; i--)
  105.     {
  106.         memcpy(*(Matrix+i-1),*(Matrix+i-2), sizeof(**Matrix)*x);
  107.     }
  108.         randomFirstRov(x, y, Matrix);
  109. }
  110.  
  111.  
  112. void randomFirstRov (int x , int y , char** Matrix)
  113. {
  114.     for(int i=0; i<x; i++)
  115.         {
  116.             *(*Matrix+i)=rnd();
  117.     }
  118. }
  119.  
  120. void showWord (int x, int y, char** Matrix, char* word, int position)
  121. {
  122.     int k = 0; //zmienna do iterowania liter w s³owie
  123.  
  124.     for(int i=0; i<strlen(word); i++) //wykonuje sie tyle razy ile liter ma s³owo
  125.     {
  126.         for(int j=0; j<x; j++) //wykonuje sie tyle razy liter wierszu
  127.         {
  128.             if(j == position) //je¿eli jesteœmy na podanej pozycji to wstawia literê ze s³owa zamiast losowaæ cyfre
  129.             {
  130.                 *(*Matrix+j)=word[k];
  131.                 k++;
  132.                 continue;
  133.  
  134.             }else
  135.             {
  136.             *(*Matrix+j) = rnd();
  137.             }
  138.         }
  139.  
  140.         for(int j=y; j>1; j--)
  141.         {
  142.              memcpy(*(Matrix+j-1),*(Matrix+j-2), sizeof(**Matrix)*x);
  143.         }
  144.     }
  145.  
  146.     MatrixG(x, y, Matrix);
  147. }
  148.  
  149.  
  150. void MatrixG(int x, int y, char** Matrix)
  151. {
  152.     char letter;
  153.     while(1 && letter!='t')
  154.     {
  155.         system("cls");
  156.  
  157.         printTable(x, y, Matrix);
  158.  
  159.         moveRovs(x, y, Matrix);
  160.  
  161.         if(kbhit())
  162.         {
  163.         letter=getch();
  164.  
  165.         }
  166.  
  167.         system("ping 127.0.0.1 -n 1 > nul");
  168.         //for(int i=0; i<100000000; i++){}
  169.  
  170.     }
  171.  
  172.     char word[] = "teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeest";
  173.     int position;
  174.  
  175.     //printf("Podaj slowo");
  176.    // scanf("%s", word);
  177.  
  178.     printf("podaj pozycje", &position);
  179.     scanf("%d", &position);
  180.  
  181.     showWord(x, y, Matrix, word, position);
  182. }
  183.