First, ORGANIZE YOUR DAMNED CODE! You cannot expect to spot errors if your code is a horrifying mess. Keep it organized and correctly tabulated.
Second, CHECK THE CODE! The code posted includes spaces after "random_". The compiler should throw a bitch-fit. If it doesn't, get a new one.
Third, CHECK YOUR RESULTS! This code works perfectly fine(once the syntax elements are fixed). It gives different values each time it's run.
$ ./code.illusionist-srand
Rock will not attack each other if you put them like this:
B4 H1 A2 C8 D3 E5 F6 G7
$ ./code.illusionist-srand
Rock will not attack each other if you put them like this:
G5 A1 B2 C3 D8 E4 H6 F7
$ ./code.illusionist-srand
Rock will not attack each other if you put them like this:
B7 H1 A2 C3 D4 E5 F8 G6
$ ./code.illusionist-srand
Rock will not attack each other if you put them like this:
B5 H1 A2 C3 D8 E4 F6 G7
$
Here's the organized & corrected code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
void create_array(int niz[]);
void random_numbers(int niz[], int k);
void random_characters(char niz[], int k);
void show_result(int niz[], char niz1[]);
int main(int argc, char *argv[]) {
int A[8];
char B[8] = {65,66,67,68,69,70,71,72};
srand(time(NULL));
create_array (A);
random_numbers(A, rand()%7+1);
random_characters(B, rand()%7+1);
puts("Rock will not attack each other if you put them like this:");
show_result(A,B);
return 0;
}
void create_array(int niz[]) {
int i;
for (i = 0; i < 8 ; i++)
niz[i] = i+1;
}
void random_numbers(int niz[], int k) {
int i,j,temp;
for (i = 0; i < 8 ; i++) {
j = k;
temp = niz[i];
niz[i] = niz[j];
niz[j] = temp;
}
}
void random_characters(char niz[], int k) {
int i,j,temp;
for (i = 0; i < 8 ; i++) {
j = k;
temp = niz[i];
niz[i] = niz[j];
niz[j] = temp;
}
}
void show_result(int niz[], char niz1[]) {
int i;
for(i=0;i < 8 ; i++)
printf("%c%d ",niz1[i],niz[i]);
printf("\n");
}