There's so much here, it's hard to know where to start, but lets begin here:
int pos_rand(char *array)
{
srand(time(NULL));
return (rand() % 10) * 2 + 1; }
First off, there doesn't seem to be any point to the argument
char *array
as
array
is not used anywhere in the array.
Secondly,
srand()
is only used to seed the random number generator, and would normally only be used
once per program. Consider the following program:
#include <stdlib.h>
#include <time.h>
int getrand()
{
srand(time(NULL));
return rand();
}
int main()
{
for(int i = 0; i < 10; ++i)
printf("%d\n", getrand());
return 0;
}
The output for this program might look like this:
$ ./example
1824823912
1824823912
1824823912
1824823912
1824823912
1824823912
1824823912
1824823912
1824823912
$
What's happening here is that
rand()
gets its starting point reset every time, so as long as the call to
getrand()
is within the same second on the clock, it will return the same value.
Then there's this usage: *(array + i). Unless you're working on an obfuscated C program, that's not how you would typically access the i'th element of an array. The normal way to do it is
array[i]
Next make sure you've compiled your program with -g option (adds in info for debugger) e.g. gcc -Wall -Wextra -g myprog.c -o myprog
Then use gdb to take examine what's going on
You may want to look at the gdb documentation and find out how to run a program, get the backtrace, change frames and print the values of variables.