Code:
#include <stdio.h>
#include <string.h>
int main(){
#ifdef _WIN32
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
#endif
// init input string
char input[3] = "";
char rank[5] = "";
char suit[8] = "";
int suit_index = 1;
// get input from users and store in input[]
printf("Enter the card notation: ");
scanf("%3c", input);
// A23456789JQK and 10 for rank
if(input[0] == 'A'){
// cpy Ace into rank
strncpy(rank, "Ace", 5);
} else if(input[0] == '2'){
strncpy(rank, "Two", 5);
} else if(input[0] == '3'){
strncpy(rank, "Three", 5);
} else if(input[0] == '4'){
strncpy(rank, "Four", 5);
} else if(input[0] == '5'){
strncpy(rank, "Five", 5);
} else if(input[0] == '6'){
strncpy(rank, "Six", 5);
} else if(input[0] == '7'){
strncpy(rank, "Seven", 5);
} else if(input[0] == '8'){
strncpy(rank, "Eight", 5);
} else if(input[0] == '9'){
strncpy(rank, "Nine", 5);
} else if(input[0] == '1' && input[1] == '0'){
strncpy(rank, "Ten", 5);
suit_index = 2;
} else if(input[0] == 'J'){
strncpy(rank, "Jack", 5);
} else if(input[0] == 'Q'){
strncpy(rank, "Queen", 5);
} else if(input[0] == 'K'){
strncpy(rank, "King", 5);
}
//for debug comment out when turning in assignment
// puts("Your card is");
//
//CDHS for suit
if(input[suit_index] == 'C'){
strncpy(suit, "Clubs", 8);
}
else if(input[suit_index] == 'H'){
strncpy(suit, "Hearts", 8);
}
else if(input[suit_index] == 'S'){
strncpy(suit, "Spades", 8);
}
else if(input[suit_index] == 'D'){
strncpy(suit, "Diamonds", 8);
}
if(strcmp(rank, "") != 0 && strcmp(suit, "") != 0){
printf("Your card is %s of %s\n", rank, suit);
} else {
printf("Unknown\n");
}
return 0;
}
Go see if you can Google that Matty.