B
Bill Cunningham
This program work fine except if it is run with argc==0 it seg faults. I
thought about using switch but I'm not the familiar with it so stick to the
if and else if stuff.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{
if (argc > 4 || argc == 0) {
fputs("dicegenerator usage error\n", stderr);
exit(EXIT_FAILURE);
}
int x;
x = atoi(argv[1]);
srand(time(NULL));
printf("%i\n", rand() % x);
return 0;
}
Bill
thought about using switch but I'm not the familiar with it so stick to the
if and else if stuff.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{
if (argc > 4 || argc == 0) {
fputs("dicegenerator usage error\n", stderr);
exit(EXIT_FAILURE);
}
int x;
x = atoi(argv[1]);
srand(time(NULL));
printf("%i\n", rand() % x);
return 0;
}
Bill