-
Audit this simple code?
Mind just checking this code out for me? It should compile fine and generally be error free, although I'm realeasing it on my website, and I dont want there to be too many nastys in it. If there is a better way of doing things, please do let me know. It's a simple random number generator.
Code is here: http://www.jwread.com/projects/randgen.cpp
-
#include <stdlib.h>
#include <time.h>
No need to include stdlib.h, you already included cstdlib.
Also time.h should be ctime
2. Both exit paths of main return 0.
There is EXIT_SUCCESS and EXIT_FAILURE, so I would like to see EXIT_FAILURE whenever the program fails to perform it's intended function.
> cout << "Correct useage: [numbers]\n";
When outputting error or help information, it's normal to use cerr
> count = 1;
Given the prior test of argc, I don't think this line can ever be reached.
> if (argv[1])
Again, given the previous argc test, this test is trivially true.
argv[argc] is always NULL and all the argv before then will be non-NULL.
> count = atoi(argv[1]);
A better function is strtod(), which returns more error information, for example if there is overflow.
> for(int i = 0; i <= count; i++)
This executes one more time that you expect.
If you ask for say 2 numbers, you'll get 3
> printf("%d\n", rand()%10);
Using printf() in a C++ program.