Sponsored Content
Top Forums Programming Need help with Card Dealing Program Post 302508346 by Izzy123 on Monday 28th of March 2011 01:02:08 AM
Old 03-28-2011
Need help with Card Dealing Program

I'm currently making a card dealing program, it is suppose to display a list of cards like this:
"Ace of Heart, is red"
"Two of Heart, is red"
.
.
"Ace of Spade, is black"
and so on for all suits and numbers.

here is my current code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct card { 
 const char *face;
 const char *suit;
 const char *color;
};

typedef struct card Card;
typedef unsigned char pairs;

const char *face[] = { "Ace", "Two", "Three", "Four", "Five","Six", "Seven",
                                  "Eight", "Nine", "Ten","Jack", "Queen", "King"};
const char *suit[] = { "Hearts", "Diamonds", "Clubs", "Spades"};
const char *color[]= {"Black","Red"};
void printdeck( const Card * const );
void fillDeck( Card * const, const char *[], const char *[] ,const char *[]);
void deal(card cards[52], card hands[5][5]);
int main()
{
int hand,cd,winner;
card hands[5][5],handssorted[5][5];
pairs numpairs[5],highest;
Card deck[52];
srand( time( NULL) );
fillDeck( deck, face, suit, color );
printdeck(deck);
printf("\n ----------------------------------------------------------\n");

system("pause");
return 0;

}
//------------------------------------------------------------------------------------------------------
void fillDeck( Card * const wDeck, const char * wFace[], const char * wSuit[], const char * wColor[])
{
		   int i;
		   for ( i = 0; i <= 51; i++ ) { 
		      wDeck[i].face  = wFace[ i % 13 ];
		      wDeck[i].suit  = wSuit[ i / 13 ];
		      wDeck[i].color = wColor[i%2];
        }
}
//-----------------------------------------------------------------------------------------------------
void shuffle( Card * const wDeck )
{
		   int i, j;
		   Card temp;
		   for ( i = 0; i <= 51; i++ ) { 
		      j = rand() % 52;
		      temp = wDeck[ i ];
		      wDeck[ i ] = wDeck[ j ];
		      wDeck[ j ] = temp;
}
}
//-----------------------------------------------------------------------------------------------------------
void printdeck( const Card * const wDeck )
{
           int i;
		   for ( i = 0; i <= 51; i++ ){
		      printf( "\t%s\t of \t%-8s is \t%s \n \t", wDeck[i].face, 
		              wDeck[i].suit,wDeck[i].color,
		             ( i + 1 ) % 2 ? '\t' : '\n' );}
}

but the output i get it wrong because it shows:
"Ace of Hearts is Black"
"Two of Hearts is Red"
"Three of Hearts is Black"
.
.
the color displayed is wrong. Im not sure what im doing wrong, can anyone pls help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in dealing with arra

I am readinga file lin by line and based craeting a arry of unique elemenst from the second column of the line. However when i coem out of the while loop my array becomes empty , can eny one tell me what I would be doing wrong #!/bin/bash logfile="./mylog.dat" begin=100 end="$(( $begin +... (5 Replies)
Discussion started by: jojan
5 Replies

2. UNIX Desktop Questions & Answers

Does Red Hat Fedora support Nvidia card 8800GTX and 260 card?

Does Red Hat Fedora support Nvidia card 8800GTX and 260 card? Does any Linux OS support Nvidia card? (1 Reply)
Discussion started by: sito
1 Replies

3. UNIX and Linux Applications

webinject - dealing with popups

Hello We have a webapp that launches a link in a popup. We need to use webinject to check the content of that popup but have been so far unsuccessful. We use webinject as a nagios plugin. Does anyone have any experience of using/configuring webinject and know if this is possible or not? ... (1 Reply)
Discussion started by: skewbie
1 Replies

4. Shell Programming and Scripting

Dealing with files with spaces in the name

Hello, I'm a computer science major and I'm having problems dealing with file names with spaces in them. Particularly I'm saving a file name in a variable and then using the variable in a compare function i.e. a='te xt.txt' b='file2.txt' cmp $a $b If anyone could help me with this particular... (10 Replies)
Discussion started by: jakethegreycat
10 Replies

5. Shell Programming and Scripting

cp not dealing with variable properly? please help

I am having trouble with a script that is supposed to : a)take all the jpg pictures in a given directory/parameter and create thumbnails of it in a directory on the desktop. e.g from /here/are/the/files.jpg to ~/Desktop/parser-the/files.png this is my script: all the individual parts... (2 Replies)
Discussion started by: orochinagi
2 Replies

6. UNIX and Linux Applications

Dealing with geany core

Geany : Home Page, the text editor, sometimes crashes and leaves a geany.core file. This is a binary file and supposedly contains all unsaved work and possibly some other information. Does anyone know how to deal with this file? (2 Replies)
Discussion started by: figaro
2 Replies

7. Shell Programming and Scripting

Dealing with multiple files

Korn Shell I have hundreds of small files like below created every day. A midnight cron job moves them to the location /u04/temp/logs But sometimes I have to manually move these files based a certain dates or time. I have two basic requirements 1.Using mv command I want to move all .dat... (2 Replies)
Discussion started by: kraljic
2 Replies

8. UNIX for Dummies Questions & Answers

Dealing with sum

I have file input 1/1/2013 1AS030A 0 1083 CHINA 1/1/2013 1AS030B 0 675 KOREA 1/1/2013 1AS035A 162 662 CHINA 1/1/2013 1AS035B 51 799 INDIA 1/1/2013 1AS035C 0 731 CHINA 1/2/2013 1AS073A 10 1375 KOREA... (5 Replies)
Discussion started by: radius
5 Replies

9. Shell Programming and Scripting

Dealing with edge-list

I have an edge-list with nodes, edge.txt A B B J J H C A G H G A A C K G I have another file which tells me which of these nodes are important, input.txt G C A (3 Replies)
Discussion started by: Sanchari
3 Replies

10. Programming

Dealing with XML comments

I'm writing my own simple XML parser as an experiment. It's a lot more complicated than it's supposed to be. Things supposedly forbidden in XML comments happen all the time in the wild. You're never, ever supposed to find -- inside <!-- xml comments --> but in practice, you don't just find... (2 Replies)
Discussion started by: Corona688
2 Replies
Ace::Graphics::Glyph::group(3pm)			User Contributed Perl Documentation			  Ace::Graphics::Glyph::group(3pm)

NAME
Ace::Graphics::Glyph::group - The group glyph SYNOPSIS
none DESCRIPTION
This is an internal glyph type, used by Ace::Graphics::Track for moving sets of glyphs around as a group. This glyph is created automatically when processing a set of features passed to Ace::Graphics::Panel->new as an array ref. OPTIONS In addition to the common options, the following glyph-specific options are recognized: Option Description Default ------ ----------- ------- -connect Whether to connect members false of the group by a dashed line. BUGS
Please report them. SEE ALSO
Ace::Sequence, Ace::Sequence::Feature, Ace::Graphics::Panel, Ace::Graphics::Track, Ace::Graphics::Glyph::anchored_arrow, Ace::Graphics::Glyph::arrow, Ace::Graphics::Glyph::box, Ace::Graphics::Glyph::primers, Ace::Graphics::Glyph::segments, Ace::Graphics::Glyph::toomany, Ace::Graphics::Glyph::transcript, AUTHOR
Lincoln Stein <lstein@cshl.org>. Copyright (c) 2001 Cold Spring Harbor Laboratory This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See DISCLAIMER.txt for disclaimers of warranty. perl v5.14.2 2001-02-20 Ace::Graphics::Glyph::group(3pm)
All times are GMT -4. The time now is 05:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy