mardi 10 mars 2015

How do I make a function print out a certain amount of Random numbers through the command line? C

How do I pass an arguement and print that amount of numbers in my program? So far I have found out that if I change count to a lower number than argc, the amount of numbers increases. However, I want it to print x amount of numbers on whatever I type in the command line like 10. Thanks



int random( int limi, int lims);

int main (int argc, char *argv[])
{
int count;
srand(time(NULL));
int p;
int input;
int i = 0;


if (argc > 1)
{
for ( count = 1; count < argc; count++)
{

p = random(-10000,10000);

printf(" %d\n",p );


}
}
else
{
printf("The command had no other arguments.\n");
}

return 0;
}

int random( int limi, int lims )
{
return ( rand() % (lims - limi) - lims);
}




Aucun commentaire:

Enregistrer un commentaire