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

void marquee(int cycle, const char *text, const char *base);

int main()
{
    const char *s = "Hello";
    const char t[] = "**********";
    int cycle = 0;

    printf("cycle?\n");
    scanf("%d", &cycle);
    if (cycle < 1) { cycle = 1; }
    marquee(cycle, s, t);

    return 0;
}

static void display(int pos, const char *text, int len_text, const char *base, int len_base);

void marquee(int cycle, const char *text, const char *base)
{
    int len_text = (int)strlen(text);
    int len_base = (int)strlen(base);
    int pos = 0;

    while (cycle >= 0) {
        display(pos, text, len_text, base, len_base);

        pos--;
        if (pos == -1) { cycle--; }
        if (pos <= -len_text) { pos = len_base - 1; }
    }
}

static void display(int pos, const char *text, int len_text, const char *base, int len_base)
{
    int i;
    for (i = 0; i < len_base; i++) {
        int j = i - pos;
        putchar(0 <= j && j < len_text ? text[j] : base[i]);
    }
    putchar('\n');
}
