X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=samples%2Fsieve.c;h=cb6783c935ad4e997fdb76c928301b7c439a1451;hb=d184d938fd31424397847b985841ff45e5c4a94c;hp=e04fc6fcae74f2493d0a175952af789c6b533fad;hpb=0bb81e5c369bf6f191f6b23d0ae334b7c23b353a;p=cc65 diff --git a/samples/sieve.c b/samples/sieve.c index e04fc6fca..cb6783c93 100644 --- a/samples/sieve.c +++ b/samples/sieve.c @@ -26,11 +26,15 @@ static unsigned char Sieve[COUNT]; /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ +#pragma staticlocals(1); + + + int main (void) { /* Clock variable */ @@ -41,6 +45,11 @@ int main (void) register unsigned I; register unsigned J; + /* Output a header */ + printf ("Sieve benchmark - calculating primes\n"); + printf ("between 2 and %u\n", COUNT); + printf ("Please wait patiently ...\n"); + /* Read the clock */ Ticks = clock(); @@ -62,21 +71,21 @@ int main (void) /* Calculate the time used */ Ticks = clock() - Ticks; - /* Print the time used and wait for a key */ + /* Print the time used */ printf ("Time used: %lu ticks\n", Ticks); printf ("Press Q to quit, any other key for list\n"); - if (toupper (cgetc()) == 'Q') { - exit (EXIT_SUCCESS); - } - /* Print the result */ - for (I = 2; I < COUNT; ++I) { - if (Sieve[I] == 0) { - printf ("%4d\n", I); - } - if (kbhit() && toupper (cgetc()) == 'q') { - break; - } + /* Wait for a key and print the list if not 'Q' */ + if (toupper (cgetc()) != 'Q') { + /* Print the result */ + for (I = 2; I < COUNT; ++I) { + if (Sieve[I] == 0) { + printf ("%4d\n", I); + } + if (kbhit() && toupper (cgetc()) == 'Q') { + break; + } + } } return EXIT_SUCCESS;