Edited! Thanks! I thought at least I should not post *BAD* examples for new programmers
Edited! Thanks! I thought at least I should not post *BAD* examples for new programmers
Yes, it's longer, but wow is it easier to understand and use!Code:#include <iostream> const char fontMap[][5][4] = { { "XXX", "X X", "X X", "X X", "XXX" }, { " X ", "XX ", " X ", " X ", "XXX" }, { "XXX", " X", "XXX", "X ", "XXX" }, { "XXX", " X", "XXX", " X", "XXX" }, { "X X", "X X", "XXX", " X", " X" }, { "XXX", "X ", "XXX", " X", "XXX" }, { "XXX", "X ", "XXX", "X X", "XXX" }, { "XXX", " X", " X", " X", " X" }, { "XXX", "X X", "XXX", "X X", "XXX" }, { "XXX", "X X", "XXX", " X", "XXX", } }; const int FONT_HEIGHT = 5; using std::cout; int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage\n\taa.py <number>\n"); return 1; } long number = strtol(argv[1], NULL, 10); if (number == 0 && argv[1][0] != '0') { cout << "Error: Only digits allowed!\n"; return 1; } int length = strlen(argv[1]); for (int j = 0; j < FONT_HEIGHT; j++) // For every line of the font array { for (int i = 0; i < length; i++) // For every number of the command argument { int number = argv[1][i] - '0'; cout << fontMap[number][j] << " "; } cout << "\n"; } return 0; }
:p pppppppp
Do you also mean that your version does exactly the same as my version??
This is my output, for 5577:
Post your output??Code:@@@ @@@ @@@ @@@ @ @ @ @ @@@ @@@ @ @ @ @ @ @ @@@ @@@ @ @
That's an entirely different issue. Your code was confusing as it is.
I'll do a few modifications and you'll see it will work fine.
123456789:
Code:X XXX XXX X X XXX XXX XXX XXX XXX XX X X X X X X X X X X X X XXX XXX XXX XXX XXX X XXX XXX X X X X X X X X X X X XXX XXX XXX X XXX XXX X XXX XXX
Honestly yours came out simpler and better, because you arranged the font map better!
But that was my point, I wanted to make it obfuscated, so that font map does not give away the looks of fonts!
Oh, and by the way I can change my font style from 'X' to '@' to '#' to 'M' by changing a single char in the code!
Can you??
How?
You are lucky that there is no other 'X' except in your font map
How about doing this:
I just had to change:Code:555 555 777 777 5 5 7 7 555 555 7 7 5 5 7 7 555 555 7 7
Code:putchar(fontMap[row][i1]=='0' ? ' ' : number[col]);