summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--games/primes/primes.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/games/primes/primes.c b/games/primes/primes.c
index 359c109..e928885 100644
--- a/games/primes/primes.c
+++ b/games/primes/primes.c
@@ -101,8 +101,8 @@ extern ubig *pr_limit; /* largest prime in the prime array */
extern char pattern[];
extern int pattern_size; /* length of pattern array */
-void primes __P((ubig, ubig, int));
-ubig read_num_buf __P((int));
+void primes __P((ubig, ubig));
+ubig read_num_buf __P((void));
void usage __P((void));
int
@@ -114,13 +114,9 @@ main(argc, argv)
ubig stop; /* don't generate at or above this value */
int ch;
char *p;
- int hexa = 0;
- while ((ch = getopt(argc, argv, "h")) != EOF)
+ while ((ch = getopt(argc, argv, "")) != -1)
switch (ch) {
- case 'h':
- hexa = 1;
- break;
case '?':
default:
usage();
@@ -144,14 +140,14 @@ main(argc, argv)
errx(1, "negative numbers aren't permitted.");
errno = 0;
- start = strtoul(argv[0], &p, 0);
+ start = strtoul(argv[0], &p, 10);
if (errno)
err(1, "%s", argv[0]);
if (*p != '\0')
errx(1, "%s: illegal numeric format.", argv[0]);
errno = 0;
- stop = strtoul(argv[1], &p, 0);
+ stop = strtoul(argv[1], &p, 10);
if (errno)
err(1, "%s", argv[1]);
if (*p != '\0')
@@ -163,14 +159,14 @@ main(argc, argv)
errx(1, "negative numbers aren't permitted.");
errno = 0;
- start = strtoul(argv[0], &p, 0);
+ start = strtoul(argv[0], &p, 10);
if (errno)
err(1, "%s", argv[0]);
if (*p != '\0')
errx(1, "%s: illegal numeric format.", argv[0]);
break;
case 0:
- start = read_num_buf(hexa);
+ start = read_num_buf();
break;
default:
usage();
@@ -178,7 +174,7 @@ main(argc, argv)
if (start > stop)
errx(1, "start value must be less than stop value.");
- primes(start, stop, hexa);
+ primes(start, stop);
exit(0);
}
@@ -187,7 +183,7 @@ main(argc, argv)
* This routine returns a number n, where 0 <= n && n <= BIG.
*/
ubig
-read_num_buf(int hexa)
+read_num_buf()
{
ubig val;
char *p, buf[100]; /* > max number of digits. */
@@ -204,7 +200,7 @@ read_num_buf(int hexa)
if (*p == '-')
errx(1, "negative numbers aren't permitted.");
errno = 0;
- val = strtoul(buf, &p, 0);
+ val = strtoul(buf, &p, 10);
if (errno)
err(1, "%s", buf);
if (*p != '\n')
@@ -217,10 +213,9 @@ read_num_buf(int hexa)
* primes - sieve and print primes from start up to and but not including stop
*/
void
-primes(start, stop, hexa)
+primes(start, stop)
ubig start; /* where to start generating */
ubig stop; /* don't generate at or above this value */
- int hexa;
{
register char *q; /* sieve spot */
register ubig factor; /* index and factor */
@@ -261,7 +256,7 @@ primes(start, stop, hexa)
for (p = &prime[0], factor = prime[0];
factor < stop && p <= pr_limit; factor = *(++p)) {
if (factor >= start) {
- printf(hexa ? "0x%x\n" : "%u\n", factor);
+ printf("%lu\n", factor);
}
}
/* return early if we are done */
@@ -324,7 +319,7 @@ primes(start, stop, hexa)
*/
for (q = table; q < tab_lim; ++q, start+=2) {
if (*q) {
- printf(hexa ? "0x%x\n" : "%u\n", start);
+ printf("%lu\n", start);
}
}
}
OpenPOWER on IntegriCloud