Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- //#include <thread>
- //#define _CRT_SECURE_NO_WARNINGS
- #define POCETZNAKU 62
- #define SOUBOR "random1.dat"
- //const char* SOUBOR = "random1.dat";
- //FILE *fp;
- int pocetVlaken = 1000; /// TODO argument pri spusteni programu
- char poleZnaku[POCETZNAKU] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
- void vytvorSoubor(int);
- int FileScan();
- void producenti(int, char*);
- int main(int argc, char* argv[]) {
- //pocetVlaken = argv[1];
- vytvorSoubor(1000000);
- int velikostSouboru = FileScan();
- int velikostBloku = velikostSouboru / pocetVlaken;;
- int posledniBlok = velikostSouboru % pocetVlaken; // pricist k poslednimu vlaknu
- FILE *file;
- file = fopen(SOUBOR, "r");
- rewind(file);
- int i;
- for (i = 0; i < pocetVlaken; i++){
- if (i == pocetVlaken) //posledni vlakno
- {
- char *p = malloc(velikostBloku + posledniBlok);//new char[velikostBloku + posledniBlok];
- for (int b = 0; b < velikostBloku + posledniBlok; b++)
- {
- p[b] = fgetc(file);
- }
- producenti(velikostBloku + posledniBlok, p);
- // predani pole p vlaknu
- }
- else
- {
- char *p = malloc(velikostBloku);//[velikostBloku];
- for (int b = 0; b < velikostBloku; b++)
- {
- p[b] = fgetc(file);
- }
- printf("asdasdad %d", velikostBloku);
- getchar();
- producenti(velikostBloku, p);
- // predani pole p vlaknu
- }
- }
- fclose(file);
- //// vlakna
- /*pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(
- &attr, PTHREAD_CREATE_DETACHED);
- pthread_create(NULL, &attr, &function, NULL);*/
- return EXIT_SUCCESS;
- }
- void vytvorSoubor(int velikost)
- {
- FILE *file;
- file = fopen(SOUBOR, "w");
- int i, j;
- for (i = 0; i<velikost; i++)
- {
- j = (int)rand() % POCETZNAKU;
- putc(poleZnaku[j], file); // pole Znaku = predem definovane znaky
- }
- printf("Vytvoren soubor");
- fclose(file);
- }
- int FileScan()
- {
- FILE *file;
- file = fopen(SOUBOR, "r");
- char c;
- int pocetZnaku = 0;
- while (!feof(file))
- {
- c = fgetc(file);
- pocetZnaku = pocetZnaku + 1;
- }
- printf("pocet znaku v souboru %d", pocetZnaku-1);
- fclose(file);
- return pocetZnaku-1;
- }
- void producenti(int blok, char *p)
- {
- //FILE *f;
- //file = fopen(SOUBOR, "r");
- int *cetnosti = calloc(POCETZNAKU, sizeof(int)); // alokace pole velikosti POCETZNAKU * INT a vyplni hodnoty na 0
- for (int i = 0; i < blok; i++)
- {
- printf("%c %d\n", p[i], i);
- for (int j = 0; j < POCETZNAKU; j++)
- {
- if (poleZnaku[j] == p[i])
- {
- cetnosti[j] += 1;
- }
- }
- }
- getchar();
- for (int i = 0; i < POCETZNAKU; i++) // tisk vysledku
- {
- printf("cetnosti %c %d \n", poleZnaku[i], cetnosti[i]);
- }
- }
- void* konzumer()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement