Eclipse Console Does't Output Anything - c

When I run my code, the console doesn't output anything. When I go into "debug as c application mode" and step into the makeBoard() method that is supposed to print stuff nothing is shown on the console. I can't work on this project if the console doesn't work.
Whenever I run my code with only makeBoard() in the int main(void) method, the console outputs what it's supposed to. However, when I add the rest of my code in the int main(void) method, nothing is shown in the console window.
I am very new to C and the eclipse IDE. Do I need to download something?
The makeBoard() method:
void makeBoard(){
printf("Row A: ");
for(int i = 0; i< rowAcounter; i++)
{
printf("O");
}
printf("\n");
printf("Row B: ");
for(int i = 0; i< rowBcounter; i++)
{
printf("O");
}
printf("\n");
printf("Row C: ");
for(int i = 0; i< rowCcounter; i++)
{
printf("O");
}
printf("\n");
}
My complete int main method and the rest of my program:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
void makeBoard();
void nextTurn(int player);
void prompt(int turn);
_Bool isGameOver();
void done(int currentTurn);
void test();
void update();
int rowAcounter = 3;
int rowBcounter = 5;
int rowCcounter = 8;
int currentPlayer = 0; // 0= player 1's turn, 1
= player 2's turn
char firstIn;
char secondIn;
_Bool flag = 0;
int main(void){
makeBoard();
while(isGameOver() == 0){
prompt(currentPlayer);
update();
nextTurn(currentPlayer);
if(flag == 1){
break;
}
makeBoard();
}
done(currentPlayer);
return 0;
}
the rest of my code:
void update(){
poll: scanf(" %c%c", &firstIn, &secondIn);
int checkFirst = firstIn - 'A';
if((checkFirst < 0) || (checkFirst > 2))
{
printf("\n Try again, you ape.");
goto poll;
}
int checkSecond = secondIn - '0';
if((checkSecond < 0 ) || (checkSecond > 8)){
printf("\n Try again, you fricker.");
goto poll;
}
else if(checkFirst == 0){ // the player chose row A
if(checkSecond > 3){
printf("\n Try again, you frick.");
goto poll;
}
else{
rowAcounter = rowAcounter - checkSecond;
}
}
else if(checkFirst == 1){ // the player chose row B
if(checkSecond > 5){
printf("\n Try again, you headass.");
goto poll;
}
else{
rowBcounter = rowBcounter - checkSecond;
}
}
else{ // the player chose row C
if(checkSecond > 8)
{
printf("\n Try again!");
goto poll;
}
else{
rowCcounter = rowCcounter - checkSecond;
}
}
if(isGameOver() == 1){
flag = 1;
}
}
void nextTurn(int player){
if(player == 0){
player = 1;
}else
{
player = 0;
}
}
void prompt(int turn){
if(turn == 0){
printf("Player 1, make your move:");
}
else{
printf("Player 2, make your move:");
}
}
_Bool isGameOver(){
if((rowAcounter == 0) && (rowBcounter == 0) && (rowCcounter == 0)){
return 1;
}
else{
return 0;
}
}
void done(int currentTurn){
if(currentTurn == 0){
puts("Player 1 wins!");
}
else{
puts("Player 2 wins!");
}
}

Related

Minimax going in order(Tic Tac Toe)

I'm currently trying to make use of the Minimax Algorithm and create a "Unbeatable Computer Player". I'm banging my head with this one for hours now and I cant seem to figure out why the "Computer" is going in order and not making the right decisions. Does anybody have an idea? maybe something sticks out for you I can't put my finger on what's wrong honestly. I bet it has something to do with the recursive call but I'm lost here.
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
char BOARD[9][4];
void createBoard(){
for(int i = 0;i < 9;i++){
strcpy(BOARD[i], "[]");
}
strcpy(BOARD[6], "[X]");
strcpy(BOARD[1], "[O]");
strcpy(BOARD[3], "[X]");
}
void printBoard(){
printf("\n\n");
for(int i = 0;i < 9;i++){
printf("%s", BOARD[i]);
if((i + 1) % 3 == 0){
printf("\n");
}
}
printf("\n\n");
}
void makeMove(char* player, int position){
char playerFinal[5];
strcpy(playerFinal, "[");
strcat(playerFinal, player);
strcat(playerFinal, "]");
if(strcmp(BOARD[position], "[]") == 0){
strcpy(BOARD[position], playerFinal);
}
}
bool movesLeft(){
for(int i = 0;i < 9;i++){
if(strcmp(BOARD[i], "[]") == 0){
return true;
}
}
return false;
}
char* isWinner(){
for(int i = 0;i < 9;i = i + 3){
if(strcmp(BOARD[i], BOARD[i + 1]) == 0 && strcmp(BOARD[i + 1], BOARD[i + 2]) == 0){
if(strcmp(BOARD[i], "[X]") == 0){
return "X";
}
else if(strcmp(BOARD[i], "[O]") == 0){
return "O";
}
}
}
for(int i = 0;i < 3;i++){
if(strcmp(BOARD[i], BOARD[i + 3]) == 0 && strcmp(BOARD[i + 3], BOARD[i + 6]) == 0){
if(strcmp(BOARD[i], "[X]") == 0){
return "X";
}
else if(strcmp(BOARD[i], "[O]") == 0){
return "O";
}
}
}
if(strcmp(BOARD[0], BOARD[4]) == 0 && strcmp(BOARD[4], BOARD[8]) == 0){
if(strcmp(BOARD[0], "[X]") == 0){
return "X";
}
else if(strcmp(BOARD[0], "[O]") == 0){
return "O";
}
}
if(strcmp(BOARD[2], BOARD[4]) == 0 && strcmp(BOARD[4], BOARD[6]) == 0){
if(strcmp(BOARD[2], "[X]") == 0){
return "X";
}
else if(strcmp(BOARD[2], "[O]") == 0){
return "O";
}
}
if(!movesLeft()){
return "tie";
}
return "";
}
int minimax(bool isMaximizing){
char* winner = isWinner();
printf("Function Called\n");
printf("%s", winner);
if(strcmp(winner, "O") == 0){
return 10;
}
if(strcmp(winner, "X") == 0){
return -10;
}
if(strcmp(winner, "tie") == 0){
return 0;
}
if(isMaximizing){
int score;
int bestScore = -1000000;
for(int i = 0;i < 9;i++){
if(strcmp(BOARD[i], "[]") == 0){
makeMove("O", i);
score = minimax(false);
strcpy(BOARD[i], "[]");
if(score > bestScore){
bestScore = score;
}
}
}
return bestScore;
}
else{
int score;
int bestScore = 1000000;
for(int i = 0;i < 9;i++){
if(strcmp(BOARD[i], "[]") == 0){
makeMove("X", i);
score = minimax(true);
strcpy(BOARD[i], "[]");
if(score < bestScore){
bestScore = score;
}
}
}
return bestScore;
}
}
void bestMove(){
int bestScore = -1000;
int position;
for(int i = 0;i < 9;i++){
if(strcmp(BOARD[i], "[]") == 0){
int score;
makeMove("O", i);
score = minimax(false);
strcpy(BOARD[i], "[]");
printf("Position %d\n", i);
printf("Best Score %d\n", bestScore);
printf("Score %d\n", score);
if(score > bestScore){
bestScore = score;
position = i;
}
}
}
makeMove("O", position);
}
int main(){
int position;
createBoard();
printBoard();
bool player = true;
char* winner = "";
while(strcmp(winner, "") == 0){
if(player){
printf("Its the Players Turn\nChoose a Position: ");
scanf("%d", &position);
makeMove("X", position -1);
player = false;
winner = isWinner();
}
else{
printf("Its the Computers Turn");
bestMove();
player = true;
winner = isWinner();
}
printBoard();
}
printf("The Winner is: %s\n", winner);
return 0;
}

How to replace goto in my code while searching for a road in C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SPECKLE '.'
#define WALL '#'
/*char a[1000][1000] = {
{'#','.','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
{'#','.','.','.','#','.','.','.','.','.','.','.','.','.','.','.','#'},
{'#','.','#','#','#','.','#','#','#','#','#','.','#','.','#','#','#'},
{'#','.','.','.','.','.','.','.','.','.','#','.','#','.','.','.','#'},
{'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','.','#'},
};*/
#define SIZE 1000
void print_arr()
{
char a[SIZE][SIZE];
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 7; ++j)
{
printf("%c",a[i][j]);
}
printf("\n");
}
}
int main(int argc, char const *argv[])
{
int x = 0, y = 1;
char a[SIZE][SIZE];
for(int i=0;i<SIZE;i++)
{
scanf("%s",&a[i]);
}
continue_in_road:
while(1)
{
if(y == 16 && x == 4)
break;
if(a[x][y] == SPECKLE)
{
a[x][y] = '1';
y++;
continue;
}
else if(a[x][y] == WALL)
{
y--;
goto go_back_and_check;
}
go_back_and_check:
while(1)
{
if(a[x+1][y] == SPECKLE)
{
x++;
goto continue_in_road;
}
else if(a[x-1][y] == SPECKLE)
{
x--;
goto continue_in_road;
}
else if(a[x][y-1] == WALL)
{
a[x][y] = '2';
x--;
continue;
}
else if(a[x][y-1] == '1')
{
a[x][y] = '2';
y--;
continue;
}
else if(a[x][y-1] == SPECKLE)
{
y--;
goto switch_to_left;
}
}
switch_to_left:
while(1)
{
if(a[x][y] == SPECKLE)
{
a[x][y] = '1';
y--;
continue;
}
else if(a[x][y] == WALL)
{
y++;
goto go_back_and_check;
}
}
}
//print_arr();
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 18; ++j)
{
if(a[i][j] == '1')
a[i][j] = '*';
if(a[i][j] == '2')
a[i][j] = '.';
printf("%c",a[i][j]);
}
printf("\n\n");
}
// print_arr();
return 0;
}
The code is for finding the path or the road in the graph, which looks like :
Input:
Output:
I'm searching for an alternative to goto command as I would like to teach more than this command how to jump in loops. I was told that goto command is ugly and so on, so I would be happy if any of you will help me with this one.
THANKS GUYS !
Using functions is the best way to get rid of those gotos. However don't dislike gotos just because someone told you so.
Here is a good reading about goto which enlighted me about goto when I was convinced by teachers and the internet that they were the Evil. Now I love goto; it just has it's applications on which it is the best tool available:
https://koblents.com/Ches/Links/Month-Mar-2013/20-Using-Goto-in-Linux-Kernel-Code/
Great power comes with great responsibility :)
Now your code:
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SPECKLE '.'
#define WALL '#'
#define SIZE 1000
#if 01
static char aa[1000][1000] = {
{'#','.','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
{'#','.','.','.','#','.','.','.','.','.','.','.','.','.','.','.','#'},
{'#','.','#','#','#','.','#','#','#','#','#','.','#','.','#','#','#'},
{'#','.','.','.','.','.','.','.','.','.','#','.','#','.','.','.','#'},
{'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','.','#'}
};
#endif
static int x, y;
static void print_arr(void);
static void continue_in_road(char a[SIZE][SIZE]);
static bool check(char a[SIZE][SIZE]);
static void switch_to_left(char a[SIZE][SIZE]);
/*
* Note that int main(void) is completely valid, and in fact is what you need,
* because you're not using the arguments.
*/
int main(void)
{
int i, j;
// char a[SIZE][SIZE];
x = 0;
y = 1;
// for (i = 0; i < SIZE; i++)
// scanf(" %s", &a[i]);
continue_in_road(aa);
print_arr();
for (i = 0; i < 5; i++) {
for (j = 0; j < 18; j++) {
if(aa[i][j] == '1')
aa[i][j] = '*';
if(aa[i][j] == '2')
aa[i][j] = '.';
printf("%c",aa[i][j]);
}
printf("\n\n");
}
print_arr();
return 0;
}
static void continue_in_road(char a[SIZE][SIZE])
{
bool initial_chk = true;
while (1) {
if (initial_chk) {
if ((y == 16) && (x == 4))
return;
if (a[x][y] == SPECKLE) {
a[x][y] = '1';
y++;
continue;
} else if (a[x][y] == WALL) {
y--;
}
}
if (check(a)) {
initial_chk = true;
continue;
}
initial_chk = false;
switch_to_left(a);
}
}
static bool check(char a[SIZE][SIZE])
{
while (1) {
if (a[x+1][y] == SPECKLE) {
x++;
return true;
} else if (a[x-1][y] == SPECKLE) {
x--;
return true;
} else if (a[x][y-1] == WALL) {
a[x][y] = '2';
x--;
} else if (a[x][y-1] == '1') {
a[x][y] = '2';
y--;
} else if (a[x][y-1] == SPECKLE) {
y--;
return false;
}
}
}
static void switch_to_left(char a[SIZE][SIZE])
{
while (1) {
if (a[x][y] == SPECKLE) {
a[x][y] = '1';
y--;
} else if(a[x][y] == WALL) {
y++;
return;
}
}
}
/* What is this supposed to do? */
static void print_arr(void)
{
char a[SIZE][SIZE];
int i, j;
for (i = 0; i < 5; ++i) {
for (j = 0; j < 7; ++j)
printf("%c",a[i][j]);
printf("\n");
}
}
It runs if you compile it just like that. I have commented the input loop to use the static const array initializer you've created, so that it was easy to test.
However I think you should reconsider changing the structure of the functions, because it is difficult to understand what it is doing. If I had understood what it does, I could have improved more the code, but as I didn't understand it so much, I limited myself to get rid of those gotos.

Why is the computer's input not being considered?

In the code below there is an error I can't locate causing the computer's selection to not be accounted for. The user's input is being considered in the Nim game yet the computer's pieces are not being subtracted.
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
void printInstructions();
int getUserInput(int);
int randomRange(int,int);
int PlayerTurn(int);
int smartCompMove(int);
int dumbCompMove(int);
int main()
{
srand(time(NULL));
int pieceAmount = randomRange(12,24);
char smartCompOrDumb;
printf("Do you want to play a smart computer or a dumb one? Select 'S' or 'D'.");
scanf("%c",&smartCompOrDumb);
bool gameOver = false;
bool playerTurn = true;
printInstructions();
while(pieceAmount > 0 && gameOver == false)
{
if (playerTurn == false)
{
if(pieceAmount <= 4)
{
printf("\nThe Computer has won :P ");
gameOver = true;
exit(0);
}
if (smartCompOrDumb == 's' || smartCompOrDumb == 'S')
{
playerTurn = true;
pieceAmount = smartCompMove(pieceAmount);
printf("%d",pieceAmount);
}
else if (smartCompOrDumb == 'd' || smartCompOrDumb == 'D')
{
playerTurn = true;
pieceAmount = dumbCompMove(pieceAmount);
printf("%d",pieceAmount);
}
}
else
{
if(pieceAmount <= 4)
{
printf("\nYou have won :) ");
gameOver = true;
exit(0);
}
playerTurn = false;
pieceAmount = PlayerTurn(pieceAmount);
printf("%d",pieceAmount);
}
}
return 0;
}
void printInstructions()
{
printf("\nThis game is called Nim and it is thousands of years old.");
printf("\nTake turns picking one to three pieces from a pile and whomever picks the last piece wins.");
printf("\n__________________________________________________________________________________________");
}
int randomRange(int low,int high)
{
return rand()% (high - low) + low;
}
int PlayerTurn(int pieceAmount)
{
pieceAmount = getUserInput(pieceAmount);
return pieceAmount;
}
int getUserInput(int pieceAmount)
{
int userInput = 0;
bool flag = true;
while (flag == true)
{
if (pieceAmount > 4)
{
printf("\nThere are %d pieces remaining.\n",pieceAmount);
printf("\nHow many pieces do you want to select? ");
scanf("%d", &userInput);
if (userInput >= 1 && userInput < 5)
{
pieceAmount = pieceAmount - userInput;
flag = false;
}
else
{
printf("This is not a valid move so try again.");
}
}
}
return pieceAmount;
}
int dumbCompMove(int pieceAmount)
{
int dumbPick = rand() % 3 + 1;
printf("\nComputer will pick from the stack. \n");
pieceAmount = pieceAmount - dumbPick;
printf("\nComputer picked %d pieces. \n", dumbPick );
return pieceAmount;
}
int smartCompMove(int pieceAmount)
{
int smartPick = 1;
printf("\nThe computer will select their pieces. \n");
if (pieceAmount >= 15 && pieceAmount < 24)
{
smartPick = 2;
pieceAmount = pieceAmount - smartPick;
}
else if (pieceAmount >= 10 && pieceAmount < 15)
{
smartPick = 4;
pieceAmount = pieceAmount - smartPick;
}
else if (pieceAmount >= 6 && pieceAmount < 10)
{
smartPick = 1;
pieceAmount = pieceAmount -smartPick;
}
else
pieceAmount = 3;
printf("\nThe computer selected %d pieces. \n",smartPick);
return pieceAmount;
}
I had this code working earlier yet somehow I must have altered something minor and now it will not function properly. I am using the Cloud9 program to run it.

Loop incomplete

I just started learning coding for about 2 months because of the course im taking.
My code works (kinda) but after the 1st loop it wont show the 1st line of the main function("You have been given 20 pokeballs, embrak on you quest on becoming a Pokeman Master!!!:), and i dont know why!
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int pokeball = 20;
int rand_num;
int PokemonCaught[5] = { 0, 0, 0 ,0, 0 };
int poke_captured = 0;
int rungame = 1;
int stopgame = 1;
int total;
int randomnum();
int encounter_rate();
int pokemon_met();
void BallThrow();
void CaughtPokemon();
void checkball();
void PokeSummary();
char exitno();
int clear();
int main()
{
printf("You have been given 20 pokeballs, embrak on you quest on becoming a Pokeman Master!!!\n");
getchar();
do
{
checkball();
encounter_rate();
pokemon_met();
} while (stopgame == 0);
PokeSummary();
return 0;
}
int randomnum()
{
srand(time(NULL));
}
int encounter_rate()
{
randomnum();
rand_num = rand() % 100;
}
int pokemon_met()
{
if (rand_num <= 30)
{
printf("A wild Margikarp appeared!.\n");
printf("Press ENTER to throw a pokeball!. \n");
getchar();
rungame = 1;
BallThrow();
}
else if (rand_num <= 50)
{
printf("A wild Charmander appeared!.\n");
printf("Press ENTER to throw a pokeball!. \n");
getchar();
rungame = 1;
BallThrow();
}
else if (rand_num <= 70)
{
printf("A wild Jigglypuff appeared!.\n");
printf("Press ENTER to throw a pokeball!. \n");
getchar();
rungame = 1;
BallThrow();
}
else if (rand_num <= 85)
{
printf("A wild Pikachu appeared!.\n");
printf("Press ENTER to throw a pokeball!. \n");
getchar();
rungame = 1;
BallThrow();
}
else
{
printf("A wild Dragonite appeared!.\n");
printf("Press ENTER to throw a pokeball!. \n");
getchar();
rungame = 1;
BallThrow();
}
}
void checkball()
{
if (pokeball > 0)
{
stopgame = 0;
}
else
{
stopgame = 1;
}
}
void BallThrow()
{
randomnum();
int BallChance;
int PokeRun;
BallChance = rand() % 2;
pokeball = pokeball - 1;
if (BallChance == 1)
{
printf("Gotcha!\n");
printf("Number of Pokeball left: %d\n", pokeball);
printf("Press ENTER to continue your journey!\n\n");
poke_captured = poke_captured + 1;
CaughtPokemon();
getchar();
if (pokeball == 0)
{
printf("Your pokeball has used up!\n");
printf("Press ENTER to check the summary of your journey\n");
getchar();
PokeSummary();
}
}
else if (BallChance == 0)
{
PokeRun = rand() % 2;
printf("The pokemon broke free!!!\n");
if (PokeRun == 0)
{
if (pokeball == 0)
{
printf("Your pokeball has used up!\n");
printf("Press ENTER to check the summary of your journey\n");
getchar();
PokeSummary();
}
else
{
printf("Number of Pokeball left: %d\n", pokeball);
printf("Press ENTER to throw pokeball!\n\n");
getchar();
BallThrow();
}
}
else if (PokeRun == 1)
{
printf("Oh no! The pokemon ran away!\n");
printf("Number of Pokeball left: %d\n", pokeball);
printf("Press ENTER to continue your journey!\n\n");
getchar();
if (pokeball == 0)
{
printf("Your pokeball has used up!\n");
printf("Press ENTER to check the summary of your journey\n");
getchar();
PokeSummary();
}
}
}
}
void CaughtPokemon()
{
if (rand_num <= 30)
{
PokemonCaught[0] = PokemonCaught[0] + 1;
}
else if (rand_num <= 50)
{
PokemonCaught[1] = PokemonCaught[1] + 1;
}
else if (rand_num <= 70)
{
PokemonCaught[2] = PokemonCaught[2] + 1;
}
else if (rand_num <= 85)
{
PokemonCaught[3] = PokemonCaught[3] + 1;
}
else if (rand_num <= 95)
{
PokemonCaught[4] = PokemonCaught[4] + 1;
}
}
void PokeSummary()
{
int point0, point1, point2, point3, point4, total;
point0 = (PokemonCaught[0]) * 10;
point1 = (PokemonCaught[1]) * 30;
point2 = (PokemonCaught[2]) * 30;
point3 = (PokemonCaught[3]) * 50;
point4 = (PokemonCaught[4]) * 70;
total = point0 + point1 + point2 + point3 + point4;
printf("You have successfully caught %d Pokemon!\n\n", poke_captured);
printf("You have caught:\n");
printf("Margikarp = %d (%dpoints)\n", PokemonCaught[0], point0);
printf("Charmander = %d (%dpoints)\n", PokemonCaught[1], point1);
printf("Jigglypuff = %d (%dpoints)\n", PokemonCaught[2], point2);
printf("Pikachu = %d (%dpoints)\n", PokemonCaught[3], point3);
printf("Dragonite = %d (%dpoints)\n", PokemonCaught[4], point4);
printf("\nTotal points = %d\n", total);
exitno();
}
char exitno()
{
char stay;
printf("Press 'y' to continue, press any other key to quit.");
scanf(" %c", &stay);
if (stay == 'y' || stay == 'Y')
{
clear();
return (main);
}
else
{
printf("Thank you for playing!!");
exit(0);
}
}
int clear()
{
total = total * 0;
poke_captured = poke_captured * 0;
PokemonCaught[0] = PokemonCaught[0] * 0;
PokemonCaught[1] = PokemonCaught[1] * 0;
PokemonCaught[2] = PokemonCaught[2] * 0;
PokemonCaught[3] = PokemonCaught[3] * 0;
PokemonCaught[4] = PokemonCaught[4] * 0;
pokeball = pokeball + 20;
}
I appreciate any help and i know my codes are far from being decent (sigh)
. Thanks
You have made an error when calling main in char exitno() function:
char exitno()
{
char stay;
printf("Press 'y' to continue, press any other key to quit.");
scanf(" %c", &stay);
if (stay == 'y' || stay == 'Y')
{
clear();
return ((char)main()); // main it should be called using parenthesis
}
else
{
printf("Thank you for playing!!");
exit(0);
}
}
That is not inside of your do-while loop.
If you want it to execute every time, then just move it down into the the loop. Otherwise, your program will move past in the first few milliseconds of operation. Alternatively, modify it (likely, put it within a new function) to print out some information that might change during execution of your program--say, the current number of pokeballs remaining.

Having trouble coming up with a 'display function' or added functionality - c

Finishing up a program and been told that I need to have the cards be displayed after the user quits.
Tried having draw return the hand variable and printing that, and storing each result of the draw(), which I had turned to int; although I am showing you the working function, which is void.
So far nothing works and I am lost.
void draw(int deck[SIZE], int a) {
int numCards = 10;
int i;
int hand[numCards];
int card;
for(i = 0; i < numCards && top > 0; i++) {
card = deck[top-1];
hand[i] = card;
top--;
}
if(a != 0) {
printcards(card);
} else {
for(i = 0; i < numCards && top > 0; i++)
printcards(card);
}
}
Program can print off cards as drawn and edited version looks like:
int draw(int deck[SIZE], int a) {
int numCards = 10;
int i;
int hand[numCards];
int card;
for(i = 0; i < numCards && top > 0; i++) {
card = deck[top-1];
hand[i] = card;
top--;
}
if(a != 0) {
printcards(card);
} else {
for(i = 0; i < numCards && top > 0; i++)
printcards(card);
}
return card; /* or return hand */
}
void printcards(int card) {
char suits[4][9] = {
"Hearts",
"Diamonds",
"Clubs",
"Spades"
};
if(card%13 == 0 || card%13 == 10 || card%13 == 11 || card%13 == 12) {
printf("%s ", facecheck(card%13) );
} else {
printf("%d ", card%13+1);
}
printf("of %s \n", suits[card/13]);
}
This function is the actual printing of cards:
void players(int deck[]) {
int x;
int a;
int yourhand[10];
a = 1;
printf("Player 1 \n");
printf("Your Hand is: \n");
draw(deck, a);
draw(deck, a);
while(a == 1) {
printf("What would you like to do: Press 1 to Draw. 2 to Stay. \n");
scanf("%d" , &x);
if(x == 1) {
draw(deck, a);
} else {
a--;
}
}
}
This function calls the draw() with user input, then need to add a display() after the else, before a-- or store result of draw into your hand and print result. So far nothing has worked.

Resources