Advertisement
PaulGalindoIsart

scrolling.c

Aug 3rd, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1.  
  2. #include "functions.h"
  3.  
  4. int main(int argc, char* argv[])
  5. {
  6.     // Optional argv[1]: String to display
  7.     const char* str = "Bonjour je m'appelle Benjamin";
  8.     if (argc >= 2)
  9.         str = argv[1];
  10.  
  11.     // Optional argv[2]: delay between ticks in (ms)
  12.     int delay = 500;
  13.     if (argc >= 3)
  14.         delay = string_to_number(argv[2]);
  15.  
  16.     int str_length = string_length(str);
  17.     int tick = 0;
  18.     while (true) // Infinite loop (Ctrl-C to stop)
  19.     {
  20.         // First chararacter to display is at str[scroll_index]
  21.         // It will loop from 0 to str_length-1
  22.         unsigned int scroll_index = tick % str_length;
  23.  
  24.         put_string(&str[scroll_index]);  // Display the end of string (from str[index] to '\0' char)
  25.         put_string_n(str, scroll_index); // Display the start of string (from str[0] to str[scroll_index-1])
  26.         put_char('\r');                  // Carriage return
  27.         update_output();
  28.        
  29.         sleep_ms(delay);
  30.         tick++;                          // Update tick for next loop
  31.     }
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement