Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as C by jstc ( 12 years ago )
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void vypis_pole(short int cykl, unsigned int pole[])
{
    unsigned short int b;
    printf("Prvky pole (%2i):\n", cykl);
    for (b = 0; b < 256 / 2; b++)
        printf("%2u: %u\t\t%2u: %u\n", b + 1, pole[b], b + 256 / 2 + 1,
        pole[b + 256 / 2]);
}


int main()
{
    /* Promene, pole */
    int i;
    int ch;
    int nacteny_znak;
    unsigned int cykl, bublani, pom;

    unsigned int pole_znaku[256];

    /* Cyklus pro vytvoreni pole prvku kde kazdy se bude rovnat 0, a a cislo pole treba a[107]=vyskyt, 107 = ascii kod pro pismeno k */
    for (i = 0; i < 256; i++)
        pole_znaku[i] = 0;

    /* Nacteni souboru, cteni po pismenu a zapisovani pismena do pole znaku */
    FILE *input;
    if (input = fopen&#40;"fred.txt", "rt"&#41;)
    {
    ch = getc(input);
        while (ch != EOF)
        {
            nacteny_znak = ch;
            pole_znaku[nacteny_znak]++;
            printf("%c\n", ch);
            printf("%i\n", nacteny_znak);
            printf("------------------------\n");
            ch = getc(input);
        }
    fclose(input);
    }

    printf("%i\n", pole_znaku[97]);

    vypis_pole(-1, pole_znaku);

    for (cykl = 1; cykl < 256; cykl++) {
        for (bublani = 256 - 1; bublani >= cykl; bublani--) {
            printf(".");
            if (pole_znaku[bublani - 1] > pole_znaku[bublani]) {
                pom = pole_znaku[bublani - 1];
                pole_znaku[bublani - 1] = pole_znaku[bublani];
                pole_znaku[bublani] = pom;
            }
        }
        printf("\n");
        vypis_pole(cykl, pole_znaku);

    }



}

 

Revise this Paste

Your Name: Code Language: