How to output a marquee string that is smaller than the size of the marquee sign?

后端 未结 1 1007
挽巷
挽巷 2021-01-25 14:45

So my code takes in a string of letters, then outputs that string in a marquee fashion with the size of the sign being 5. So for example, If I want to output \"Hello World!\", t

相关标签:
1条回答
  • 2021-01-25 15:24

    Change the loop into this:

        if (n <= marq_length) {
            printf("[%-*s]\n", marq_length, s);
        } else {
            for (i = 0; i < n + 1; i++) {
                putchar('[');
                for (j = 0; j < marq_length; j++) {
                    char c = s[(i + j) % (n + 1)];
                    if (!c)
                        c = ' ';
                    putchar(c);
                }
                printf("]\n");
            }
        }
    
    0 讨论(0)
提交回复
热议问题