Advertisement
k_vychodilova

Ukol_3_tajenka

Feb 13th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #define VELIKOST 8000000
  6.  
  7. // const int VELIKOST 100000;
  8.  
  9. int main(int argc, char** argv) {
  10.     static char* pole[VELIKOST]; // static umožní větší velikost, je uložený v paměti globálních proměnných
  11.  
  12.     FILE *seznam= fopen("CZ.txt","r");
  13.     srand(time(NULL));
  14.            
  15.     char buffer[256];
  16.     int i = 0;
  17.     while(fscanf(seznam,"%255s", buffer)!=EOF && i < VELIKOST) {
  18.         int delka = strlen(buffer);
  19.         if(delka > 1) {
  20.             char* novy = malloc(delka+1);
  21.             strcpy(novy, buffer);
  22.             pole[i++] = novy;
  23.         }
  24.         if ( (i & (4*65536-1)) == 0)
  25.             printf("Precten %d. radek\n", i);
  26.     }
  27.  
  28.    /* int N = i;
  29.     for(i = 0; i < N; i++)
  30.         puts(pole[i]);
  31.         */
  32.     int nahodne;
  33.     int j;
  34.     char *pozice;
  35.     int delka;
  36.     char *tajenka = "tajenka";
  37.     //int pomocna=0;
  38.    
  39.     for(j=0;j<strlen(tajenka);j++)  //projit slova
  40.     {
  41.         do{
  42.         nahodne = rand() % 7000000;
  43.         pozice = strchr( pole[nahodne], tajenka[j]);  //pokud nenajde pozici=null
  44.         //pomocna=pomocna+1;
  45.         }while(pozice == NULL);  
  46.        
  47.        
  48.         delka = strlen(pozice);
  49.        
  50.         printf("pole[nahodne]\n", nahodne);
  51.        
  52.     }
  53.     getchar();
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement