forked from YuanDaYu002/ToolBank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
persent_printf.c
61 lines (49 loc) · 1002 Bytes
/
persent_printf.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <string.h>
#if 1
int main(int argc,char *argv[])
{
if(argc < 2)
{
printf("You need input 1 parameter[argv[1]](1~50)!\n ");
return -1;
}
const int numTotal = 50;
char sign[51] = {0};
memset(sign, '=', numTotal);
int numshow;//1~50
printf("argv[1] = %s\n",argv[1]);
sscanf(argv[1],"%d",&numshow);
if(numshow < 1 || numshow > 50)
{
printf("argv[1] out of range(1~50)!\n");
return -1;
}
printf("numshow = %d\n",numshow);
printf("[%-*.*s]\n", numTotal, numshow, sign);
fflush(stdout);
return 0;
}
#else
int main(int argc,char *argv[])
{
const int numTotal = 50;
char sign[51] = {0};
memset(sign, '=', numTotal);
int numshow = 0;//1~50
for(;;)
{
numshow ++;
if(numshow < 1 || numshow > 50)
{
//printf("numshow out of range(1~50)!\n");
break;
}
//printf("numshow = %d\n",numshow);
printf("[%-*.*s]", numTotal, numshow, sign);
fflush(stdout);
sleep(1);
}
return 0;
}
#endif