码迷,mamicode.com
首页 > 编程语言 > 详细

C语言实现figlet

时间:2020-05-12 00:01:02      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:clu   str   ase   strlen   c语言   let   ||   for   void   

这可能是我写过的最蠢的代码,主要是现在懒得改了,还是就这样放出来吧。

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

void print_row(char* str, int row) {
    char c;
    for (int i = 0; i < strlen(str); i++) {
        c = *(str + i);
        switch (c) {
            case ‘A‘:
                switch (row) {
                    case 1:
                        printf("        ");
                        break;
                    case 2:
                        printf("   /\\   ");
                        break;
                    case 3:
                        printf("  /  \\  ");
                        break;
                    case 4:
                        printf(" /----\\ ");
                        break;
                    case 5:
                        printf("/_/  \\_\\");
                        break;
                }
                break;
            case ‘B‘:
                switch (row) {
                    case 1:
                        printf(" ____  ");
                        break;
                    case 2:
                        printf("| __ ) ");
                        break;
                    case 3:
                        printf("|  _ \\ ");
                        break;
                    case 4:
                        printf("| |_) |");
                        break;
                    case 5:
                        printf("|____/ ");
                        break;
                }
                break;
            case ‘C‘:
                switch (row) {
                    case 1:
                        printf("  ____ ");
                        break;
                    case 2:
                        printf(" / ___|");
                        break;
                    case 3:
                        printf("| |    ");
                        break;
                    case 4:
                        printf("| |___ ");
                        break;
                    case 5:
                        printf(" \\____|");
                        break;
                }
                break;
            case ‘D‘:
                switch (row) {
                    case 1:
                        printf(" ____  ");
                        break;
                    case 2:
                        printf("|  _ \\ ");
                        break;
                    case 3:
                        printf("| | | |");
                        break;
                    case 4:
                        printf("| |_| |");
                        break;
                    case 5:
                        printf("|____/ ");
                        break;
                }
                break;
            case ‘E‘:
                switch (row) {
                    case 1:
                        printf(" _____ ");
                        break;
                    case 2:
                        printf("| ____|");
                        break;
                    case 3:
                        printf("|  _|  ");
                        break;
                    case 4:
                        printf("| |___ ");
                        break;
                    case 5:
                        printf("|_____|");
                }
                break;
            case ‘F‘:
                switch (row) {
                    case 1:
                        printf(" _____ ");
                        break;
                    case 2:
                        printf("|  ___|");
                        break;
                    case 3:
                        printf("| |_   ");
                        break;
                    case 4:
                        printf("|  _|  ");
                        break;
                    case 5:
                        printf("|_|    ");
                        break;
                }
                break;
            case ‘G‘:
                switch (row) {
                    case 1:
                        printf("  ____ ");
                        break;
                    case 2:
                        printf(" / ___|");
                        break;
                    case 3:
                        printf("| |  _ ");
                        break;
                    case 4:
                        printf("| |_| |");
                        break;
                    case 5:
                        printf(" \\____|");
                        break;
                }
                break;
            case ‘H‘:
                switch (row) {
                    case 1:
                        printf(" _   _ ");
                        break;
                    case 2:
                        printf("| | | |");
                        break;
                    case 3:
                        printf("| |_| |");
                        break;
                    case 4:
                        printf("|  _  |");
                        break;
                    case 5:
                        printf("|_| |_|");
                        break;
                }
                break;
            case ‘I‘:
                switch (row) {
                    case 1:
                        printf(" ____ ");
                        break;
                    case 2:
                        printf("|_  _|");
                        break;
                    case 3:
                    case 4:
                        printf(" |  | ");
                        break;
                    case 5:
                        printf("|____|");
                        break;
                }
                break;
            case ‘J‘:
                switch (row) {
                    case 1:
                        printf("     _ ");
                        break;
                    case 2:
                        printf("    | |");
                        break;
                    case 3:
                        printf(" _  | |");
                        break;
                    case 4:
                        printf("| |_| |");
                        break;
                    case 5:
                        printf(" \\___/ ");
                        break;
                }
                break;
            case ‘K‘:
                switch (row) {
                    case 1:
                        printf(" _  __");
                        break;
                    case 2:
                        printf("| |/ /");
                        break;
                    case 3:
                        printf("| ‘ / ");
                        break;
                    case 4:
                        printf("| | \\ ");
                        break;
                    case 5:
                        printf("|_|\\_\\");
                        break;
                }
                break;
            case ‘M‘:
                switch (row) {
                    case 1:
                        printf(" __  __ ");
                        break;
                    case 2:
                        printf("|  \\/  |");
                        break;
                    case 3:
                        printf("| |\\/| |");
                        break;
                    case 4:
                        printf("| |  | |");
                        break;
                    case 5:
                        printf("|_|  |_|");
                        break;
                }
                break;
            case ‘L‘:
                switch (row) {
                    case 1:
                        printf(" _     ");
                        break;
                    case 2:
                    case 3:
                        printf("| |    ");
                        break;
                    case 4:
                        printf("| |___ ");
                        break;
                    case 5:
                        printf("|_____|");
                        break;
                }
                break;
            case ‘N‘:
                switch (row) {
                    case 1:
                        printf(" _   _ ");
                        break;
                    case 2:
                        printf("| \\ | |");
                        break;
                    case 3:
                        printf("|  \\| |");
                        break;
                    case 4:
                        printf("| |\\  |");
                        break;
                    case 5:
                        printf("|_| \\_|");
                        break;
                }
                break;
            case ‘O‘:
                switch (row) {
                    case 1:
                        printf("  ___  ");
                        break;
                    case 2:
                        printf(" / _ \\ ");
                        break;
                    case 3:
                        printf("| | | |");
                        break;
                    case 4:
                        printf("| |_| |");
                        break;
                    case 5:
                        printf(" \\___/ ");
                        break;
                }
                break;
            case ‘P‘:
                switch (row) {
                    case 1:
                        printf(" ____  ");
                        break;
                    case 2:
                        printf("|  _ \\ ");
                        break;
                    case 3:
                        printf("| |_) |");
                        break;
                    case 4:
                        printf("|  __/ ");
                        break;
                    case 5:
                        printf("|_|    ");
                        break;
                }
                break;
            case ‘Q‘:
                switch (row) {
                    case 1:
                        printf("  ___  ");
                        break;
                    case 2:
                        printf(" / _ \\ ");
                        break;
                    case 3:
                        printf("| | | |");
                        break;
                    case 4:
                        printf("| |_| |");
                        break;
                    case 5:
                        printf(" \\__\\_\\");
                        break;
                }
                break;
            case ‘R‘:
                switch (row) {
                    case 1:
                        printf(" ____  ");
                        break;
                    case 2:
                        printf("|  _ \\ ");
                        break;
                    case 3:
                        printf("| |_) |");
                        break;
                    case 4:
                        printf("|  _ < ");
                        break;
                    case 5:
                        printf("|_| \\_\\");
                        break;
                }
                break;
            case ‘S‘:
                switch (row) {
                    case 1:
                        printf(" ____  ");
                        break;
                    case 2:
                        printf("/ ___| ");
                        break;
                    case 3:
                        printf("\\___ \\ ");
                        break;
                    case 4:
                        printf(" ___) |");
                        break;
                    case 5:
                        printf("|____/ ");
                        break;
                }
                break;
            case ‘T‘:
                switch (row) {
                    case 1:
                        printf(" _____ ");
                        break;
                    case 2:
                        printf("|_   _|");
                        break;
                    case 3:
                    case 4:
                        printf("  | |  ");
                        break;
                    case 5:
                        printf("  |_|  ");
                        break;
                }
                break;
            case ‘U‘:
                switch (row) {
                    case 1:
                        printf(" _   _ ");
                        break;
                    case 2:
                    case 3:
                        printf("| | | |");
                        break;
                    case 4:
                        printf("| |_| |");
                        break;
                    case 5:
                        printf(" \\___/ ");
                        break;
                }
                break;
            case ‘V‘:
                switch (row) {
                    case 1:
                        printf("__     __");
                        break;
                    case 2:
                        printf("\\ \\   / /");
                        break;
                    case 3:
                        printf(" \\ \\ / / ");
                        break;
                    case 4:
                        printf("  \\ V /  ");
                        break;
                    case 5:
                        printf("   \\_/   ");
                        break;
                }
                break;
            case ‘W‘:
                switch (row) {
                    case 1:
                        printf("__        __");
                        break;
                    case 2:
                        printf("\\ \\      / /");
                        break;
                    case 3:
                        printf(" \\ \\ /\\ / / ");
                        break;
                    case 4:
                        printf("  \\ V  V /  ");
                        break;
                    case 5:
                        printf("   \\_/\\_/   ");
                        break;
                }
                break;
            case ‘X‘:
                switch (row) {
                    case 1:
                        printf("__  __");
                        break;
                    case 2:
                        printf("\\ \\/ /");
                        break;
                    case 3:
                        printf(" \\  / ");
                        break;
                    case 4:
                        printf(" /  \\ ");
                        break;
                    case 5:
                        printf("/_/\\_\\");
                        break;
                }
                break;
            case ‘Y‘:
                switch (row) {
                    case 1:
                        printf("__   __");
                        break;
                    case 2:
                        printf("\\ \\ / /");
                        break;
                    case 3:
                        printf(" \\ V / ");
                        break;
                    case 4:
                        printf("  | |  ");
                        break;
                    case 5:
                        printf("  |_|  ");
                }
                break;
            case ‘Z‘:
                switch (row) {
                    case 1:
                        printf(" _____");
                        break;
                    case 2:
                        printf("|__  /");
                        break;
                    case 3:
                        printf("  / / ");
                        break;
                    case 4:
                        printf(" / /_ ");
                        break;
                    case 5:
                        printf("/____|");
                        break;
                }
                break;
            default:
                break;
        }
        printf(" ");
    }
    printf("\n");
}


//only upper case supported
void print_str(char* str) {
    int i;
    for (i = 0; i < strlen(str); i++) {
        if (*(str + i) > ‘Z‘ || *(str + i) < ‘A‘) {
            fprintf(stderr, "only upper case string supported\n");
            return ;
        }
    }
    for (i = 1; i <= 5; i++) {
        print_row(str, i);
    }
}

C语言实现figlet

标签:clu   str   ase   strlen   c语言   let   ||   for   void   

原文地址:https://www.cnblogs.com/lunar-ubuntu/p/12872870.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!