#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;
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
]); }
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKdm9pZCBtYXJxdWVlKGludCBjeWNsZSwgY29uc3QgY2hhciAqdGV4dCwgY29uc3QgY2hhciAqYmFzZSk7CgppbnQgbWFpbigpCnsKICAgIGNvbnN0IGNoYXIgKnMgPSAiSGVsbG8iOwogICAgY29uc3QgY2hhciB0W10gPSAiKioqKioqKioqKiI7CiAgICBpbnQgY3ljbGUgPSAwOwoKICAgIHByaW50ZigiY3ljbGU/XG4iKTsKICAgIHNjYW5mKCIlZCIsICZjeWNsZSk7CiAgICBpZiAoY3ljbGUgPCAxKSB7IGN5Y2xlID0gMTsgfQogICAgbWFycXVlZShjeWNsZSwgcywgdCk7CgogICAgcmV0dXJuIDA7Cn0KCnN0YXRpYyB2b2lkIGRpc3BsYXkoaW50IHBvcywgY29uc3QgY2hhciAqdGV4dCwgaW50IGxlbl90ZXh0LCBjb25zdCBjaGFyICpiYXNlLCBpbnQgbGVuX2Jhc2UpOwoKdm9pZCBtYXJxdWVlKGludCBjeWNsZSwgY29uc3QgY2hhciAqdGV4dCwgY29uc3QgY2hhciAqYmFzZSkKew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