Is there any way to modify this function so that it removes the previous element in the array - C -


so i've been given task of modifying previous code (which simulates deck of card) more accuarely having cards in array removed after drawn.

i know there ways using linked list i'm still new using linked list , because i'm on strict timeline not mention doing how i've been taught i'd have change code uses arrays, structs , pointers cost time don't have.

void draw(int deck[size]) {     int numcards = 10;     int i;      int hand[numcards];     int card;     for(i = 0; < numcards; i++)     {         card = deck[i];              hand[i] = card;              cards(card);      } } 

this current fucuntion need modify when card added hand[i] card removed deck[i] don't repeats.

cards function prints cards , can ignore

#include <stdio.h> #include <string.h> #include <stdlib.h> #define size 52  enum faces{ace = 0, jack = 10, queen, king}; char * facecheck(int d);  void shuffle( int deck[]); void draw(int deck[size]);  void cards(int hand);  int i; int main()  {      int deck[size], i, n;     char suits[4][9] =      {         "hearts",         "diamonds",         "clubs",         "spades"     };       srand( time( null ) ) ;      for(i = 0; i<size; i++)     {         deck[i] = i;     };      shuffle(deck);     draw(deck);     shuffle(deck);      draw(deck);        return 0;  }   

this current main function, shuffle think , draw function need modify because, though randomly cycles through cards, if run enough 2 cards can appear in same hand.

you can use special card (-1) indicates deletion. hence:

card = deck[i];      hand[i] = card; deck[i] = -1; // deleted   cards(card); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -