function prototype with array

This is a discussion on function prototype with array within the C Programming forums, part of the General Programming Boards category; Hi everyone, So this is kind of a broad question , but my textbook is pretty terrible at explaining some ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Location
    British Columbia, B.C.
    Posts
    30

    function prototype with array

    Hi everyone,

    So this is kind of a broad question , but my textbook is pretty terrible at explaining some fundamental things about modular programming. I'm writing a blackjack program and I have about 8 different function prototypes:

    void clean (void);
    int GetTestChoice();
    void Initialize_Deck(int deck[]);
    int Random_Number();
    void Shuffle_Deck(int deck[]);
    int Draw_One_Card(int deck[]);
    void Display_Card(int card);
    int Score_Card(int card);
    char Users_Turn(int deck[]);

    my question is this:

    For my function Users_Turn I need to use Draw_One_Card to get a card then pass this value to Display_Card which in turn passes the cards value to Score_Card.

    How do i pass this value between one another? I find this really confusing. The books I have don't show complicated enough programs to use as an example. Usually they values the programs in my text obtain are from the users input and then transferred to a function prototype.

    Right now I'm trying to call all of my functions from User's turn but it doesn't look right.

    I'd really appreciate some outside thoughts on this. If you need me to clarify anything please let me know.

    Sincerely,

    Melodia

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You described yourself what you need to do.

    "I need to use Draw_One_Card to get a card then pass this value to Display_Card"
    Code:
    int card;
    card = Draw_One_Card(deck);
    Display_Card(card);
    deck is a shuffled array.

    "which in turn passes the cards value to Score_Card."
    Code:
    void Display_Card(int card) {
         Score_Card(card)
    altho your prototype for Score_Card returns an int, which I am not sure what the purpose of that will be. Perhaps you meant "and also pass the value to Score_Card, then add the value returned by Score_Card to the user's score?"
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    British Columbia, B.C.
    Posts
    30
    Thank you so much! For some reason(maybe I've been staring at this for way too long) my head couldn't wrap it's way around this! I really really appreciate it!

    -Melodia

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    British Columbia, B.C.
    Posts
    30
    Sorry, the second part I incorrectly explained, display card is void because it simply prints to the screen the cards suit and it's rank. Draw_One_Card is supposed to pass the 'card' to both Display_Card, and Score_Card and Score_Card is then supposed to pass it's value to calculate the users total score altogether.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21