reorder

Un outil pour réarranger les lignes de stdin - retour accueil

git clone git://bebou.netlib.re/reorder
Log | Files | Refs | README |

commit 48ad2b2c7af6c6be0e9b2f732fea5544c60330b7
parent 599bd4af5adda1304bc3b51741191fe96ca244ce
Auteurice: Arthur Pons <arthur.pons@unistra.fr>
Date:   Fri, 17 Jan 2025 12:33:49 +0100

Début factorisation ajout des cartes aux piles

Diffstat:
Mreorder.c | 20+++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/reorder.c b/reorder.c @@ -21,7 +21,7 @@ void addcardtopile(char* cardname, struct pile* p) { p->cardCount++; } -struct pile* file2pile(FILE *fp) { +struct pile file2pile(FILE *fp) { struct pile pi; struct pile *p=&pi; p->cardCount=0; @@ -30,7 +30,7 @@ struct pile* file2pile(FILE *fp) { while (fgets(line, sizeof(line), fp)) { addcardtopile(line, p); } - return p; + return pi; } int main(int argc, char **argv) { @@ -39,10 +39,12 @@ int main(int argc, char **argv) { FILE *fp = fopen("deck", "r"); - struct pile* h = file2pile(fp); - struct pile hand = *h; + struct pile hand = file2pile(fp); + struct pile *h = &hand; struct pile played; - played.cardCount = 0; + struct pile *p=&played; + played.cards=malloc(LIST_SIZE); + played.cardCount=0; tb_init(); bool selection=false; @@ -128,9 +130,7 @@ int main(int argc, char **argv) { case 65515: if (curmenu=="played") { if (selection) { - hand.cards[hand.cardCount] = malloc(256); - strcpy(hand.cards[hand.cardCount], played.cards[curline]); - hand.cardCount++; + addcardtopile(played.cards[curline],h); played.cardCount--; for(int w=curline;w<played.cardCount;w++) { played.cards[w]=played.cards[w+1]; @@ -144,9 +144,7 @@ int main(int argc, char **argv) { case 65514: if (curmenu=="hand") { if (selection) { - played.cards[played.cardCount] = malloc(256); - strcpy(played.cards[played.cardCount], hand.cards[curline]); - played.cardCount++; + addcardtopile(hand.cards[curline],p); hand.cardCount--; for(int w=curline;w<hand.cardCount;w++) { hand.cards[w]=hand.cards[w+1];