Skip to content

Commit

Permalink
use unsigned long with factor
Browse files Browse the repository at this point in the history
  • Loading branch information
izabera authored and landley committed Feb 10, 2016
1 parent 93e27d0 commit e8427bf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions toys/other/factor.c
Expand Up @@ -19,22 +19,22 @@ config FACTOR

static void factor(char *s)
{
long l, ll;
unsigned long l, ll;

for (;;) {
char *err = s;

while(isspace(*s)) s++;
if (!*s) return;

l = strtol(s, &s, 0);
l = strtoul(s, &s, 0);
if (*s && !isspace(*s)) {
error_msg("%s: not integer", err);

return;
}

printf("%ld:", l);
printf("%lu:", l);

// Negative numbers have -1 as a factor
if (l < 0) {
Expand All @@ -44,7 +44,7 @@ static void factor(char *s)

// Nothing below 4 has factors
if (l < 4) {
printf(" %ld\n", l);
printf(" %lu\n", l);
continue;
}

Expand All @@ -59,11 +59,11 @@ static void factor(char *s)
long lll = ll*ll;

if (lll>l || lll<ll) {
if (l>1) printf(" %ld", l);
if (l>1) printf(" %lu", l);
break;
}
while (!(l%ll)) {
printf(" %ld", ll);
printf(" %lu", ll);
l /= ll;
}
}
Expand Down

0 comments on commit e8427bf

Please sign in to comment.