Exemple #1
0
int main(){
//    const char* max = strmax("hello","world");
//    const char* max = strmax("hello",NULL);
    const char* max = strmax("hello","hello");
    if(!max){
        printf("求字符串最大值失败!\n");
        return -1;
    }
    printf("字符串最大值:%s\n",max);
    return 0;
}
Exemple #2
0
int print_string(int msgs, char** msg)
{
    int i       = 0,
        j       = 0,
        len     = 0,
        maxlen  = strmax(msgs, msg);    /* get max length */

    /*
     * single line
     */
    putchar(' ');
    while (i <= maxlen) {
        putchar('_');
        i++;
    }
    if (msgs == 1) {
        fprintf(stdout, "\n< %s >\n ", msg[0]);

        while (maxlen >= 0) {
            putchar('-');
            maxlen--;
        }
        putchar('\n');

        return 0;
    }

    /*
     * multi line
     */
    i = 0;
    while (i < msgs) {
        j = 0;
        len = mbstrlen(msg[i]);

        if (i == 0)
            fprintf(stdout, "\n/ %s", msg[i]);
        else if (i == (msgs -1))
            fprintf(stdout, "\\ %s", msg[i]);
        else
            fprintf(stdout, "| %s", msg[i]);

        while (j < (maxlen - len)) {
            putchar(' ');
            j++;
        }

        if (i == 0)
            fprintf(stdout, " \\\n");
        else if (i == (msgs - 1))
            fprintf(stdout, " /\n ");
        else
            fprintf(stdout, " |\n");

        i++;
    }

    while (maxlen >= 0) {
        putchar('-');
        maxlen--;
    }
    putchar('\n');

    return 0;
}