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

How to do this in C?

Name: dddddddddddddddddddd 2007-07-21 5:55 ID:YIX+bdt/

OK guys so I hear C is so awesome how would I do this?

[code]retry action = action `catch` (const $ threadDelay (5*10^6) >> retry action)[code]

basically I want a function that takes an function, executes it, then if it fails it should wait five seconds, repeating this until success

Name: Anonymous 2007-07-21 6:07 ID:VB5Svegx


#include <time.h>
#include <stdio.h>
#include <stdlib.h>

#ifdef WIN32
#include <windows.h>
#define sleep Sleep
#endif

typedef uint8_t fail_func(void);

void retry( fail_func * action )
{
    while( !action() )
    {
        printf( "Failed\n" );
        sleep( 5 );
    }

    printf( "Success\n" );
}

uint8_t some_action(void)
{
    return !( rand() % 10 );
}

int main( int argc, char ** argv )
{
    srand( time( NULL ) );
    retry( some_action );
    return 1;
}

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