I do not know what I did to my vscode but not it does not display anything, sometimes even a simple printf
. The code runs and then terminates without results. I have installed gcc as the compiler and set it to run in terminal. Here is the code
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void bubble_sort(int *deck, int size);
int main() {
srand(time(NULL));
char *suits[] = { "Hearts", "Clubs", "Diamonds", "Spades" };
char *ranks[] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
int deck[52];
for (int i = 0; i < 52; i++) {
deck[i] = i;
}
int index1 = 0, index2 = 0;
for (int i = 0; i < 50; i++) {
index1 = (rand() % 51);
index2 = (rand() % 51);
int temp = deck[index1];
deck[index1] = deck[index2];
deck[index2] = temp;
}
int count = 0;
for (int i = 0; i < 52; i++) {
printf("%s of %s\n", ranks[deck[i] % 13], suits[deck[i] / 13]);
}
bubble_sort(deck, 52);
for (int i = 0; i < 52; i++) {
printf("%s of %s\n", ranks[deck[i] % 13], suits[deck[i] / 13]);
}
}
void bubble_sort(int *deck, int size) {
int temp = 0;
for (int i = 0; i < size; i++) {
for (int j = 1; j < size; j++) {
if (deck[j] > deck[j - 1]) {
temp = deck[j];
deck[j] = deck[j - 1];
deck[j - 1] = temp;
}
}
}
}
Result- it only displays the concatenated name
PS C:\Users\Macharia Mbugua\OneDrive\Desktop\cc++\.vscode\Array_Stuff> cd "c:\Users\Macharia Mbugua\OneDrive\Desktop\cc++\.vscode\Array_Stuff\" ; if ($?) { gcc ShowCards2.c -o ShowCards2 } ; if ($?) { .\ShowCards2 }
Joe Mbugua
PS C:\Users\Macharia Mbugua\OneDrive\Desktop\cc++\.vscode\Array_Stuff> cd "c:\Users\Macharia Mbugua\OneDrive\Desktop\cc++\.vscode\Array_Stuff\" ; if ($?) { gcc ShowCards2.c -o ShowCards2 } ; if ($?) { .\ShowCards2 }
Joe Mbugua
PS C:\Users\Macharia Mbugua\OneDrive\Desktop\cc++\.vscode\Array_Stuff>
I have tried restarting and reinstalling VScode but nothing works. The expected results should be a list of cards in random order then a list of sorted cards