1
- #include <stdlib.h>
2
1
#include <stdio.h>
2
+ #include <stdlib.h>
3
3
#include <math.h>
4
4
5
5
#include "common.h"
6
6
7
-
8
-
9
- float
10
- percentage (unsigned long int n , unsigned long int d )
11
- {
12
- /* TBD: Error check here */
13
- float percent = ((float )n / (float )d )* 100.0 ;
7
+ float percentage (uint64_t n , uint64_t d ) {
8
+ /* TODO: Error check here */
9
+ float percent = ((float )n / (float )d ) * 100.0 ;
14
10
return percent ;
15
11
}
16
12
17
-
18
- int
19
- str_comp (const void * key , const void * memb )
20
- {
13
+ int str_comp (const void * key , const void * memb ) {
21
14
const char * * a = (const char * * )key ;
22
15
const char * * b = (const char * * )memb ;
23
16
return strcmp (* a , * b );
24
17
}
25
18
26
- int
27
- int_comp (const void * key , const void * memb )
28
- {
19
+ int int_comp (const void * key , const void * memb ) {
29
20
const int a = * (int * )key ;
30
21
const int b = * (int * )memb ;
31
22
if (a == b )
@@ -34,16 +25,13 @@ int_comp(const void *key, const void *memb)
34
25
return -1 ;
35
26
}
36
27
37
-
38
- char *
39
- grep_awk (FILE * fp , const char * fstr , int nfield , const char * delim )
40
- {
28
+ char * grep_awk (FILE * fp , const char * fstr , int nfield , const char * delim ) {
41
29
char * ret = NULL ;
42
30
int i ;
43
31
char * line = (char * )calloc (500 , sizeof (char ));
44
32
check_mem (line );
45
33
while (fgets (line , 400 , fp ) != NULL ) {
46
- if (strncasecmp (line , fstr , strlen (fstr )) == 0 ){
34
+ if (strncasecmp (line , fstr , strlen (fstr )) == 0 ) {
47
35
ret = strtok (line , delim );
48
36
for (i = 0 ; i < nfield ; i ++ ) {
49
37
ret = strtok (NULL , delim );
@@ -58,28 +46,26 @@ grep_awk(FILE *fp, const char *fstr, int nfield, const char *delim)
58
46
}
59
47
free (line );
60
48
return NULL ;
61
- error :
49
+ error :
62
50
return NULL ;
63
51
}
64
52
65
- char *
66
- squeeze (char * string , const char * chars )
67
- {
53
+ char * squeeze (char * string , const char * chars ) {
68
54
char * src = string ;
69
55
char * target = string ;
70
56
char ch ;
71
- for (; * chars ; chars ++ ) {
72
- ch = * chars ;
57
+ for (; * chars ; chars ++ ) {
58
+ ch = * chars ;
73
59
src = string ;
74
60
target = string ;
75
- while (* src != '\0' ) {
61
+ while (* src != '\0' ) {
76
62
if (* src != ch ) {
77
63
* target = * src ;
78
64
target ++ ;
79
- }
65
+ }
80
66
src ++ ;
81
67
}
82
- * target = '\0' ;
68
+ * target = '\0' ;
83
69
}
84
70
return string ;
85
71
}
0 commit comments