Last active
December 13, 2016 09:30
-
-
Save vidul-nikolaev-petrov/037e3a89b63dde53b346d7dfb4c30bf8 to your computer and use it in GitHub Desktop.
Printable ascii characters (tiny helper)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* | |
The conversion from `int` to `char` in this sequence is not to guaranteed to work on all systems. | |
See more in the comments of the accepted answer: http://stackoverflow.com/questions/21196926 | |
*/ | |
int main() { | |
int i; | |
int e = 0; | |
char numbers[11]; | |
char alpha_capital[27]; | |
char alpha_lower[27]; | |
char alphanumeric[11 + 2 * 27 + 1]; | |
char *label[] = { | |
"numbers", | |
"ALPHABET", | |
"alphabet", | |
"special chars", | |
"alphanumeric" | |
}; | |
void print_title(char *s); | |
void print_content(char *s); | |
print_title(label[0]); | |
for (i = 48; i < 58; i++) { | |
numbers[e++] = i; | |
printf("%c:%d ", numbers[e-1], i); | |
} | |
numbers[e] = '\0'; e = 0; | |
print_content(numbers); | |
print_title(label[1]); | |
for (i = 65; i < 91; i++) { | |
alpha_capital[e++] = i; | |
printf("%c:%d ", alpha_capital[e-1], i); | |
} | |
alpha_capital[e] = '\0'; e = 0; | |
print_content(alpha_capital); | |
print_title(label[2]); | |
for (i = 97; i < 123; i++) { | |
alpha_lower[e++] = i; | |
printf("%c:%d ", alpha_lower[e-1], i); | |
} | |
alpha_lower[e] = '\0'; e = 0; | |
print_content(alpha_lower); | |
print_title(label[3]); | |
for (i = 33; i < 126; i++) { | |
if (i == 48) { | |
i += 9; | |
continue; | |
} | |
if (i == 65) { | |
i += 25; | |
continue; | |
} | |
if (i == 97) { | |
i += 25; | |
continue; | |
} | |
printf("%c ", i); | |
} | |
sprintf(alphanumeric, "%s%s%s", alpha_capital, alpha_lower, numbers); | |
printf("\n\n%s\n%6s%s\n", label[4], "", alphanumeric); | |
} | |
void print_title(char *s) { | |
printf("%s\n%6s", s, ""); | |
} | |
void print_content(char *s) { | |
printf("\n%6s%s\n\n", "", s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment