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;
}
Name:
Anonymous
2007-07-21 6:24
ID:Heaven
smaller than your code haskell fag.
for(int(*f)()=fun;f();sleep(5));
btw, i suppose your fun() returns 0 for success.
Name:
Anonymous
2007-07-21 7:11
ID:JK3jDiXx
>>2
Sleep() takes milliseconds.
Name:
Anonymous
2007-07-21 8:18
ID:Heaven
>>4
You're right. I just wanted it to compile on MingW.
Name:
Anonymous
2009-01-14 12:26
LISP
Name:
Anonymous
2009-03-06 5:58
reference for that function with the function is merely a collection of exisitng technologies yet the marketing put them like its sum.
Name:
2010-10-24 18:27