Subversion Repositories programming

Rev

Rev 294 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 294 Rev 298
Line 36... Line 36...
36
    int i;
36
    int i;
37
    int c = -1;
37
    int c = -1;
38
    int n = -1;
38
    int n = -1;
39
    int min = INT_MAX;
39
    int min = INT_MAX;
40
    int max = INT_MIN;
40
    int max = INT_MIN;
41
    unsigned int seed = 1;
-
 
42
 
41
 
43
    int *numbers;
42
    int *numbers;
44
 
43
 
45
    /* Parse the command line options */
44
    /* Parse the command line options */
46
    opterr = 0;
45
    opterr = 0;
47
 
46
 
48
    while ((c = getopt (argc, argv, "s:n:")) != -1)
47
    while ((c = getopt (argc, argv, "n:")) != -1)
49
    {
48
    {
50
        switch (c)
49
        switch (c)
51
        {
50
        {
52
 
51
 
53
            /* Try to get n */
52
            /* Try to get n */
54
            case 'n':
53
            case 'n':
55
                n = atoi (optarg);
54
                n = atoi (optarg);
56
                break;
55
                break;
57
 
56
 
58
            /* Try to get a seed (optional) */
-
 
59
            case 's':
-
 
60
                seed = atoi (optarg);
-
 
61
                break;
-
 
62
 
-
 
63
            /* Catch bad options */
57
            /* Catch bad options */
64
            case '?':
58
            case '?':
65
                if (isprint (optopt))
59
                if (isprint (optopt))
66
                    fprintf (stderr, "Unknown option '-%c'.\n", optopt);
60
                    fprintf (stderr, "Unknown option '-%c'.\n", optopt);
67
                else
61
                else
Line 73... Line 67...
73
                abort ();
67
                abort ();
74
        }
68
        }
75
    }
69
    }
76
 
70
 
77
    /* Seed the random number generator */
71
    /* Seed the random number generator */
78
    srand (seed);
72
    srand (time(NULL));
79
 
73
 
80
    /* Check if the n value is valid */
74
    /* Check if the n value is valid */
81
    if (n<=0)
75
    if (n<=0)
82
    {
76
    {
83
        fprintf (stderr, "Bad value for n, must be greater than 0\n");
77
        fprintf (stderr, "Bad value for n, must be greater than 0\n");