Author Topic: I took up Xires' offer.  (Read 1342 times)

0 Members and 1 Guest are viewing this topic.

Offline Polyphony

  • VIP
  • Knight
  • *
  • Posts: 178
  • Cookies: 23
    • View Profile
I took up Xires' offer.
« on: October 25, 2012, 04:02:44 am »
His little challenge was to write a program that will print out a deck of cards, but I'm having some trouble with what seems to be a little fluke in the code or something.
Code: [Select]
This is main.c
http://pastebin.com/dnFaHccJ

and this is main.h
http://pastebin.com/pnBJKgS9

When you compile and run it with "gcc -std=gnu99 -Wall main.c main.h -o main" it prints all the things I meant for it to print
Code: [Select]
Ace of clubs
2 of clubs
3 of clubs
etc... etc..
but it does diamonds like 3 times at the end of the run, does anybody know why?  I'll continue messing with it trying to get it fixed, but one of you guys might see some obvious noob thing I messed up on.

oooh! I can't believe I forgot about the break statement.  I had forgotten alot about switch() case: statements so I googled a little and I guess forgot about breaking lol.
« Last Edit: October 25, 2012, 04:47:48 am by Polyphony »
Code: [Select]
<Spacecow_> for that matter I have trouble believing bitches are made out of ribs
<Gundilido> we are the revolutionary vanguard fighting for the peoples right to display sombrero dawning poultry
<Spacecow> did they see your doodle?
<~phage> Maybe
<+Unresolved> its just not creative enough for me
<+Unresolved> my imagination is to big to something so simple

Offline Xires

  • Noob Eater
  • Administrator
  • Knight
  • *
  • Posts: 379
  • Cookies: 149
    • View Profile
    • Feed The Trolls - Xires
Re: I took up Xires' offer.
« Reply #1 on: October 25, 2012, 04:36:20 am »
"break;"

Code: (c) [Select]
switch (variable) {
    case 0:
        do_something();
        break; /* do this so it doesn't automatically fall through & execute the others */
    case 1:
        do_something();
    case 2: /* allow fall-through to execute multiple statements */
        something_else();
        break; /* break this execution path which could include do_something() from case #1 */
    default:
        printf("wtf?\n");
}
-Xires