fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. void marquee(int cycle, const char *text, const char *base);
  6.  
  7. int main()
  8. {
  9. const char *s = "Hello";
  10. const char t[] = "**********";
  11. int cycle = 0;
  12.  
  13. printf("cycle?\n");
  14. scanf("%d", &cycle);
  15. if (cycle < 1) { cycle = 1; }
  16. marquee(cycle, s, t);
  17.  
  18. return 0;
  19. }
  20.  
  21. static void display(int pos, const char *text, int len_text, const char *base, int len_base);
  22.  
  23. void marquee(int cycle, const char *text, const char *base)
  24. {
  25. int len_text = (int)strlen(text);
  26. int len_base = (int)strlen(base);
  27. int pos = 0;
  28.  
  29. while (cycle >= 0) {
  30. display(pos, text, len_text, base, len_base);
  31.  
  32. pos--;
  33. if (pos == -1) { cycle--; }
  34. if (pos <= -len_text) { pos = len_base - 1; }
  35. }
  36. }
  37.  
  38. static void display(int pos, const char *text, int len_text, const char *base, int len_base)
  39. {
  40. int i;
  41. for (i = 0; i < len_base; i++) {
  42. int j = i - pos;
  43. putchar(0 <= j && j < len_text ? text[j] : base[i]);
  44. }
  45. putchar('\n');
  46. }
  47.  
Success #stdin #stdout 0s 1836KB
stdin
Standard input is empty
stdout
cycle?
Hello*****
ello******
llo*******
lo********
o*********
*********H
********He
*******Hel
******Hell
*****Hello
****Hello*
***Hello**
**Hello***
*Hello****
Hello*****