include stdio include windows progressbar function main void int pr sc

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <windows.h>
/* progressbar function */
main(void)
{
int pr;
scanf("%d",&pr);
system("cls");
printf("%s", progressbar(pr));
getch();
}
char *progressbar(int progress)
{
int i,k = 0;
char *prog_line = malloc(sizeof(char)*53);
prog_line[0]='[';
prog_line[51]=']';
if ((progress < 0) || (progress > 100))
{
printf("incorrect value");
getch();
exit(0);
}
for(i=1;i<=50;i++)
{
if((progress/2)>=i)
*(prog_line + i) = '#';
else
*(prog_line + i) = '.';
}
return(prog_line);
free(prog_line);
prog_line = NULL;
}