Skip to content

Instantly share code, notes, and snippets.

@JohnMertz
Last active April 10, 2020 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnMertz/9c012da0d68dee08384e to your computer and use it in GitHub Desktop.
Save JohnMertz/9c012da0d68dee08384e to your computer and use it in GitHub Desktop.
Calculate how to display a hand of cards for 80 column console
#include <stdio.h>
void main() {
int x,y,z,spaceleft,spaceright,width;
printf("|");
for (x=0;x<80;x++) {
printf(" ");
}
printf("|left card right\n");
for (x=1;x<=13;x++) {
width = 67 / x;
if (width>13) {
width = 13;
}
spaceleft = (67 - width * (x-1)) / 2;
spaceright = spaceleft + (67 - width * (x-1)) % 2;
printf("|");
for (y=0;y<spaceleft;y++) {
printf(" ");
}
for (y=1;y<x;y++) {
for (z=0;z<width;z++) {
if (z==0) printf("[");
else if (z==12) printf("]");
else printf(" ");
}
}
printf("| |");
for (y=0;y<spaceright;y++) printf(" ");
printf("|%.4d %.4d %.4d\n",spaceleft, width, spaceright);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment