Code for shuffling w /structures, pointers

#include<stdio.h> #include<time.h> #include<stdlib.h> typedef struct { char *type; char *value; } CARD; int main() { srand(time(NULL)); char *types[] = { "Diamond","Heart","Club","Spade" }; char *values[] = { "Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King" }; CARD iskambil[52], temp; int i,pos; for ( i = 0; i < 52; i++) { iskambil[i].type = types[i / 13]; iskambil[i].value = values[i %13 ]; } for ( i = 0; i < 52; i++) { printf("%s %s %p %p \n", iskambil[i].type, iskambil[i].value, iskambil[i].type, iskambil[i].value); } printf("\n\n\n"); for ( i = 0; i < 52; i++) { pos = rand() % 52; temp = iskambil[i]; iskambil[i] = iskambil[pos]; iskambil[pos] = temp; printf("%s %s %p %p \n", iskambil[i].type, iskambil[i].value, iskambil[i].type, iskambil[i].value); } getchar(); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.