Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fibonacci Butt Sort

Name: Anonymous 2009-08-16 23:08

Let us discuss the various implementations of theFIBONACCI BUTT SORT.

Name: Anonymous 2009-08-25 3:48

Guize I have written an implementation in C with UNICODE support.
[m][b][i]#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <locale.h>
#include <errno.h>

FILE* fffffffibonacci_butt_sort(FILE *s, size_t n)
{
    size_t i = 0;
    wint_t tags[] = {L'u', L'o'};
    wint_t c = WEOF;
   
    for(i = 0; i < n; ++i)
    {
        if((c = fgetwc(s)) == L'[u][/u]n')
        {
            fputwc(L'[u][/u]n', stdout);
            return s;
        }
        else if(iswspace(c))
        {
            fputwc(c, stdout);
        }
        else if(c != WEOF)
        {
            wprintf(L"[%lc]%lc[/%lc]", tags[(i%2)], c, tags[(i%2)]);
        }
        else
        {
            return NULL;
        }
    }
    return s;
}

int main()
{
    if(!setlocale(LC_CTYPE, NULL))
    {
        fwprintf(stderr, L"Warning: Locale not specified.[o][/o]n");
    }

    const size_t BUFFA_SIZE = 4096;
    wint_t c = WEOF;

    fputws(L"[b][i]", stdout);

    while((c = fgetwc(stdin)) != WEOF)
    {
        if(ungetwc(c, stdin) == WEOF)
        {
            fputws(L"Failed to ungetwc<span class="o">.[u][/u]n", stderr);
            break;
        }

        if(!fffffffibonacci_butt_sort(stdin, BUFFA_SIZE))
        {
            break;
        }
    }

    fputws(L"[/i][/b<span class="o">][u][/u]n", stdout);

    if(ferror(stdin))
    {
        perror(strerror(errno));
        fputws(L"Input error occured. Output probably corrupted."
                "Shit fucking sucks.[u][/u]n", stderr);
    }

    return 0;
}
[/i][/b][/m]


[code]#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <locale.h>
#include <errno.h>

FILE* fffffffibonacci_butt_sort(FILE *s, size_t n)
{
    size_t i = 0;
    wint_t tags[] = {L'u', L'o'};
    wint_t c = WEOF;
   
    for(i = 0; i < n; ++i)
    {
        if((c = fgetwc(s)) == L'\n')
        {
            fputwc(L'\n', stdout);
            return s;
        }
        else if(iswspace(c))
        {
            fputwc(c, stdout);
        }
        else if(c != WEOF)
        {
            wprintf(L"[%lc]%lc[/%lc]", tags[(i%2)], c, tags[(i%2)]);
        }
        else
        {
            return NULL;
        }
    }
    return s;
}

int main()
{
    if(!setlocale(LC_CTYPE, NULL))
    {
        fwprintf(stderr, L"Warning: Locale not specified.\n");
    }

    const size_t BUFFA_SIZE = 4096;
    wint_t c = WEOF;

    fputws(L"[b][i]", stdout);

    while((c = fgetwc(stdin)) != WEOF)
    {
        if(ungetwc(c, stdin) == WEOF)
        {
            fputws(L"Failed to ungetwc.\n", stderr);
            break;
        }

        if(!fffffffibonacci_butt_sort(stdin, BUFFA_SIZE))
        {
            break;
        }
    }

    fputws(L"[/i][/b]\n", stdout);

    if(ferror(stdin))
    {
        perror(strerror(errno));
        fputws(L"Input error occured. Output probably corrupted."
                "Shit fucking sucks.\n", stderr);
    }

    return 0;
}[/code]

Here's an example for UTF-8 input:
[spoiler]Invalid or incomplete multibyte or wide character: Invalid or incomplete multibyte or wide character[/spoiler]

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List