Advertisement
wilk_maciej

krzyżówka(#wadziuxxx)

Jan 9th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.66 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5.  
  6. int main(void)
  7. {
  8.     FILE *fp;
  9.    
  10.     srand(time(NULL));
  11.     char tabchar[4][256];
  12.     char tmp[256];
  13.     int n=0,draw;
  14.     int size[5];
  15.     char lastchar;
  16.     char first_char;
  17.    
  18.     if ((fp = fopen("polski.txt","r")) == NULL)
  19.     {
  20.         printf("Nie udalo sie otworzyc pliku!");
  21.         exit(0);
  22.     }
  23.  
  24.     while(fscanf(fp,"%s",tmp) != EOF)
  25.     {
  26.         n++;   
  27.     }
  28.  
  29.     draw = rand()%n +1;
  30.     int j=0;
  31.    
  32.     while (j != 4)
  33.     {
  34.         fseek(fp,0,0);     
  35.  
  36.         if (j == 0)
  37.         {
  38.             for(int i = 0; i <= draw; i++)
  39.             {
  40.                 fscanf(fp,"%s",tabchar[j]);
  41.             }
  42.  
  43.             size[j] = strlen(tabchar[j]);
  44.             first_char = tabchar[j][0];
  45.             lastchar = tabchar[j][size[j]-1];
  46.    
  47.         }
  48.  
  49.         else
  50.         {
  51.  
  52.             for( int i = 0; i <= n; i++)
  53.             {
  54.                 fscanf(fp, "%s",tabchar[j]);
  55.  
  56.                 if ( j > 1 && j <3)
  57.                 {  
  58.                     if ( tabchar[j][0] == lastchar && strlen(tabchar[j]) == size[j-2] && strlen(tabchar[j])>=3)
  59.                     {
  60.                         size[j] = strlen(tabchar[j]);
  61.                         lastchar = tabchar[j][size[j]-1];
  62.                         break;
  63.                     }
  64.                 }
  65.                 else if (j = 3){
  66.  
  67.                     char lastcharj;
  68.                     lastcharj =tabchar[j][size[j]-1];
  69.                     if (tabchar[j][0] == lastchar && strlen(tabchar[j]) == size[j-2] && strlen(tabchar[j])>=3 && lastcharj == first_char){
  70.                         size[j] = strlen(tabchar[j]);
  71.                         lastchar = tabchar[j][size[j]-1];
  72.                         break;
  73.                     }
  74.                 }  
  75.                 else
  76.                     {  
  77.                         if (tabchar[j][0] == lastchar && strlen(tabchar[j])>=3)
  78.                         {
  79.                             size[j] = strlen(tabchar[j]);
  80.                             lastchar = tabchar[j][size[j]-1];
  81.                             break;
  82.                         }
  83.                     }
  84.            
  85.             }
  86.         }
  87.  
  88.         j++;
  89.  
  90.     }
  91.    
  92.     for (int i = 0;i < 4;i++)
  93.     {
  94.         printf("%s\n",tabchar[i]);
  95.     }
  96.  
  97.     fclose(fp);
  98.  
  99.     return 0;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement