Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define N 10
- unsigned char **make(int n) {
- unsigned char **p = (unsigned char **) malloc(N * sizeof(unsigned char *));
- for (int i = 0; i < n; i++) {
- p[i] = (unsigned char *) malloc(BUFSIZ);
- sprintf((char *) p[i], "Q%d.", i);
- }
- return p;
- }
- void print_problem(unsigned char **problem, int n) {
- for (int i = 0; i < N; i++) {
- printf("%s ", problem[i]);
- }
- printf("\n");
- }
- void shuffle(unsigned char **problem, int n) {
- srand((unsigned int) time(NULL));
- for (int i = n - 1; i > 0; i--) {
- int j = rand() % (i + 1);
- unsigned char *swap = problem[i];
- problem[i] = problem[j];
- problem[j] = swap;
- }
- }
- int main(int argc, char **argv) {
- unsigned char **problem = make(N);
- printf("Before:\n");
- print_problem(problem, N);
- shuffle(problem, N);
- printf("After:\n");
- print_problem(problem, N);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement