Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C, 5 card reader

Name: Tim 2012-12-31 8:41

Looking for some to write a c program for me and possibly e-mail it to me, willing to pay and all and it must not be copied from somewhere else.

It is a program that reads one line of text input contain 2 characters for cards and a total of 5 cards. It will then post an output with a description of each card, the hand the 5 cards make and the amount of points that hand makes. It must also show an error if the input is not supported by the program.

I could write it myself but have other coursework to do and I'm quite simply lazy. Willing to pay.

Name: Anonymous 2012-12-31 8:57

You deserve to fail.

Name: Anonymous 2012-12-31 9:22

I'd do it for $20.

Name: Anonymous 2012-12-31 9:24

homework detected, proceed to /g/ pls

Name: Anonymous 2012-12-31 9:27

Thanks for your e-mail address.

Now, where's my horse scat porn again?

Name: Tim 2012-12-31 9:30

>You deserve to fail
Probably, still got a month to do it thankfully

>I'd do it for $20
Drop me an e-mail and I'd be happy paying that if it's something you haven't copied

>Thanks for your e-mail
It's a throw-away that i use for signing up places, send what you want

Name: Anonymous 2012-12-31 10:03

>>6
No, I can do this myself. Let me create a junk mail account first.

Please give more details, because I'm not sure if this is what you want:


Card> as(enter)
Ace of Spades
    Value: 50
    Description: It's traditionally seen as the highest card in the deck of playing cards, although the actual value of the card varies from game to game. In popular myth and folklore, it is also known as the "death card".

Name: Anonymous 2012-12-31 10:10

What if I don't have a phone, Google?  Retards.

Anyway, you can use this mail to contact me. This is not my Paypal account, by the way.

Name: Tim 2012-12-31 10:11

>>7

>A program that reads a 10 character input (i.e. 2H JD 4S 4C 0H) and gives an output of (2 of Hearts Jack of Diamonds 4 of Spades 4 of Clubs 10 of hearts 1 pair Score is 2) it must also display an error message if when the input value is not supported by the program i.e. 5Z

Royal Flush = 100 points
Straight flush = 75 points
Four of a king = 50 points
Full House = 25 points
Flush = 20 points
Straight = 15 points
3 of a kind = 10 points
2 pair = 5 points
1 pair = 2 points
High card = 1 point (So either An Ace, Queen, King or Jack)

Name: Anonymous 2012-12-31 10:17

>>9
Okay, that's better. I'll let you know when it's ready.

It has to be made in C, right? I'm a bit busy (Dec 31, of course), so I'll have it ready in two or three days. Is that okay or do you need it sooner?

Name: Anonymous 2012-12-31 10:19

>>9
2H JD 4S 4C 0H
That's more than 10 characters.

Name: Anonymous 2012-12-31 10:20

>>10
Yup, in C please and it's no due until the 15th, so take your time. let me know in an e-mail how much you want for it and your PayPal please.

Name: Anonymous 2012-12-31 10:22

>>11

10 normal characters, as in you type that into the input

Name: Anonymous 2012-12-31 10:27

>>13

Forced Indentation of Code 2.7.3 (default, Dec 20 2012, 12:54:36)
[GCC 4.5.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> len('2H JD 4S 4C 0H')
14

Name: Anonymous 2012-12-31 10:36

>>12
Sent.

Name: Anonymous 2012-12-31 12:05

I'm gonna need money up front and I'm not going to do your project.

Name: Anonymous 2012-12-31 12:24

And then Tim was bankrupt.

Name: The Sussman 2012-12-31 15:44

Implementing 'printinfo' is left as an exercise for the reader.

#include <ctype.h>
#include <stdio.h>
#include <string.h>

static int read(char *s, size_t n, FILE *stream)
{
    int c;

    n--;
    while ((c = getc(stream)) != EOF && !isspace(c))
        if (n) {
            *s++ = c;
            n--;
        }
    *s = '\0';
    return c;
}

static int valid(const char *str)
{
    const char *s1 = "HSCD";
    const char *s2 = "A23456789JQK";

    return strchr(s1, str[0]) && strchr(s2, str[1]) && !str[2];
}

int main(void)
{
    char cards[5][3];
    char card[sizeof cards[0]];
    size_t i = 0;
    int c;

    do {
        if ((c = read(card, sizeof card, stdin)) == EOF)
            return 0;
        if (!card[0])
            continue;
        if (!valid(card)) {
            fprintf(stderr, "invalid card: %s\n", card);
            continue;
        }
        if (i >= sizeof cards / sizeof cards[0]) {
            fprintf(stderr, "excess card given: %s\n", card);
            continue;
        }
        memcpy(cards[i++], card, sizeof card);
    } while (c != '\n');
    if (i < sizeof cards / sizeof cards[0]) {
        fprintf(stderr, "too few cards given\n");
        return main();
    }
    for (i = 0; i < sizeof cards / sizeof cards[0]; i++)
        printinfo(cards[i]);
    return main();
}

Name: 18 2012-12-31 15:48

BTW: Changing the type of cards to char [5][4] will cause input like “HAM” to be invalid.

Name: Anonymous 2012-12-31 15:54

+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++

Name: Anonymous 2012-12-31 15:59

>>18
If he's asking for something like this, do you even think he knows what memcpy, fprintf and sizeof do?

Also, do while? Read your SICP, please.

Name: Anonymous 2012-12-31 16:04

>>21
If he's asking for something like this, do you even think he knows what memcpy, fprintf and sizeof do?
No, but it's possible. In any case, this is a good opportunity for him to learn what they do.

Also, do while?
Yes. It's rare that I'll find a use for it on a day-to-day basis, but I found it to be useful for this program in particular. Do you find something wrong with this?

Read your SICP, please.
You're scippin' up the wrong tree, Jeffrey.

Name: Anonymous 2012-12-31 17:31

willing to pay anal

i wish i knew C ;_;

Name: Anonymous 2012-12-31 19:33

card.c


#include <stdio.h>
#include <stdlib.h>
#include "magic.h"

HAX MY ANUS



magic.h


#define suit(card) (card & 0x30)
#define value(card) (card & 0x0F)
#define swap(i1, i2, h) h[i1] = h[i1] ^ h[i2]; h[i2] = h[i1] ^ h[i2]; h[i1] = h[i1] ^ h[i2];
#define step(i1, i2, h) if(value(h[i1]) > value(h[i2])) {swap(i1, i2, h)}
#define sort(h) step(0, 1, h) step(0, 2, h) step(0, 3, h) step(0, 4, h) step(1, 2, h) step(1, 3, h) step(1, 4, h) step(2, 3, h) step(2, 4, h) step(3, 4, h)
#define max(a, b) ((a > b) ? a : b)
#define cardmax(h) (max( value(h[4]), max( value(h[3]), max( value(h[2]), max( value(h[0]), value(h[1]))))))
#define connected(a, b, h) ((value(h[a]) + 1) == value(h[b]))
#define equalv(a, b, h) (value(h[a]) == value(h[b]))
#define flush(h) ((suit(h[0]) == suit(h[1])) && (suit(h[1]) == suit(h[2])) && (suit(h[2]) == suit(h[3])) && (suit(h[3]) == suit(h[4])))
#define straight(h) (connected(0, 1, h) && connected(1, 2, h) && connected(2, 3, h) && connected(3, 4, h))
#define fullhouse(h) ((equalv(0, 1, h) && equalv(1, 2, h) && equalv(3, 4, h)) || (equalv(0, 1, h) && equalv(2, 3, h) && equalv(3, 4, h)))
#define fourofakind(h) ((equalv(0, 1, h) && equalv(1, 2, h) && equalv(2, 3, h)) || (equalv(1, 2, h) && equalv(2, 3, h) && equalv(3, 4, h)))
#define threeofakind(h) ((equalv(0, 1, h) && equalv(1, 2, h)) || (equalv(1, 2, h) && equalv(2, 3, h)) || (equalv(2, 3, h) && equalv(3, 4, h)))
#define twopair(h) ((equalv(0, 1, h) && (equalv(2, 3, h) || equalv(3, 4, h))) || (equalv(1, 2, h) && equalv(3, 4, h)))
#define pair(h) (equalv(0, 1, h) || equalv(1, 2, h) || equalv(2, 3, h) || equalv(3, 4, h))
#define royalflush(h) (flush(h) && straight(h) && (cardmax(h) == 0x0E))
#define straightflush(h) (flush(h) && straight(h))
#define highcard(h) (cardmax(h) > 0x0A)
#define po(p, s) else if(p) {puts(s);}
#define ppoints(h) printf(" ---- \r\n"); if(royalflush(h)) {puts("Royal Flush: 100 poitns");} po(straightflush(h), "Straight Flush: 75 points") po(fourofakind(h), "Four of a Kind: 50 points") \
    po(fullhouse(h), "Full House: 25 points") po(flush(h), "Flush: 20 points") po(straight(h), "Straight 15 points") po(threeofakind(h), "Three of a Kind: 10 points") po(twopair(h), "Two Pair: 5 points") \
    po(pair(h), "Pair: 2 points") po(highcard(h), "High Card: 1 point") else {puts("No combinations: 0 points");}
#define pcase(n, s) case n: printf(s); break;
#define pvalue(card) switch(value(card)){pcase(0x0A, "10") pcase(0x0B, "Jack") pcase(0x0C, "Queen") pcase(0x0D, "King") pcase(0x0E, "Ace") default: putchar(value(card)+48);}
#define psuit(card) switch(suit(card)){pcase(0x00, "Clubs") pcase(0x10, "Diamonds") pcase(0x20, "Hearts") pcase(0x30, "Spades")}
#define pcard(card) pvalue(card) printf(" of "); psuit(card) putchar('\r'); putchar('\n');
#define print(hand) pcard(hand[0]) pcard(hand[1]) pcard(hand[2]) pcard(hand[3]) pcard(hand[4]) ppoints(hand)
#define error puts("Input string not of form 'VS VS VS VS VS' where V is the value of the card {0-9 J Q K A} and S is the suit of the card {C D H S}"); exit(EXIT_FAILURE);
#define icase(c, n, p) case n: c = c | p; break;
#define icard(c) switch(getchar()){icase(c, '2', 2) icase(c, '3', 3) icase(c, '4', 4) icase(c, '5', 5) icase(c, '6', 6) icase(c, '7', 7) icase(c, '8', 8) icase(c, '9', 9) icase(c, '0', 10) icase(c, 'J', 11) \
    icase(c, 'Q', 12) icase(c, 'K', 13) icase(c, 'A', 14) default: error} switch(getchar()){icase(c, 'C', 0x00) icase(c, 'D', 0x10) icase(c, 'H', 0x20) icase(c, 'S', 0x30) default: error}
#define cspace if(getchar() != ' ') {error}
#define gcard(c) icard(c) cspace
#define get(h) gcard(h[0]) gcard(h[1]) gcard(h[2]) gcard(h[3]) icard(h[4])
#define c(a,b,h) h[a] == h[b]
#define check(h) if(c(0,1,h)||c(0,2,h)||c(0,3,h)||c(0,4,h)||c(1,2,h)||c(1,3,h)||c(1,4,h)||c(2,3,h)||c(2,4,h)||c(3,4,h)) {puts("You cannot have two of the same card in a hand."); exit(EXIT_FAILURE);}
#define HAX main(){
#define MY char hand[] = {0,0,0,0,0};get(hand);check(hand);sort(hand);print(hand);
#define ANUS }

Name: Anonymous 2012-12-31 19:36

>>24
After all that work I didn't even format it right. Just imagine those \ aren't there, thanks!

Name: Anonymous 2012-12-31 19:43

>>24
Wow, that's pretty cool.

Name: Anonymous 2012-12-31 19:49

>>24
YOU HELPED HIM!

Name: Anonymous 2012-12-31 19:50

>>24
Hey there, Frozen Void.

Name: Anonymous 2013-01-01 3:44

>>24
Flathead: 20 Points.

Name: Anonymous 2013-01-01 3:45

>>24
Marlin: 50 Points.

Name: Anonymous 2013-01-01 3:45

>>24
Snapper: 100 Points.

Don't change these.
Name: Email:
Entire Thread Thread List