BigOncleSam

progressbar

Jul 7th, 2018
725
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/ioctl.h>
  4. #include <unistd.h>
  5.  
  6. void fullscreen_bar(int length) {
  7.   struct winsize w;
  8.   ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
  9.   int t = w.ws_col-7;
  10.   for (int i=1;i<=length;i++){
  11.     printf("%3d ",i);
  12.     putchar('[');
  13.     for (int j=0;j<t;j++){
  14.       if (j < i*t/length)         putchar('=');
  15.       else if (j == i*t/length)   putchar('>');
  16.       else                        putchar(' ');
  17.     }
  18.     putchar(']');
  19.     //putchar('\r');
  20.     fflush(stdout);
  21.     putchar('\r');
  22.     sleep(1);
  23.   }
  24. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment