Skip to content

Instantly share code, notes, and snippets.

@lordii
Created November 24, 2014 16:03
Show Gist options
  • Save lordii/921dd2db4f1c1fe78c6d to your computer and use it in GitHub Desktop.
Save lordii/921dd2db4f1c1fe78c6d to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/*print a character bar for output to a status bar like dwm*/
/*usage charbar X, with x between 1 and 100*/
int main(int argc, char *argv[])
{
/*check the args*/
if(argc > 2)
{
printf("Too many arguments\n");
exit(1);
}
else if (argc == 1)
{
printf("One argument expected\n");
exit(1);
}
int max = 10;
int act = atoi(argv[1])/10;
char out[20] = "";
int aux,i;
if(act > 10)
exit(1);
aux = max - act;
for(i=1;i<=act;i++)
{
/*insert the symbol*/
strcat (out,"");
}
for(i=1;i<=aux;i++)
{
/*insert a whitespace*/
strcat (out," ");
}
/*print the bar*/
printf("[%s]\n",out);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment