Skip to content

Commit b8b4fdb

Browse files
committed
Change arg types for percentage, change code style
1 parent 6d032ac commit b8b4fdb

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

Diff for: common.c

+15-29
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
#include <stdlib.h>
21
#include <stdio.h>
2+
#include <stdlib.h>
33
#include <math.h>
44

55
#include "common.h"
66

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;
1410
return percent;
1511
}
1612

17-
18-
int
19-
str_comp(const void *key, const void *memb)
20-
{
13+
int str_comp(const void *key, const void *memb) {
2114
const char **a = (const char **)key;
2215
const char **b = (const char **)memb;
2316
return strcmp(*a, *b);
2417
}
2518

26-
int
27-
int_comp(const void *key, const void *memb)
28-
{
19+
int int_comp(const void *key, const void *memb) {
2920
const int a = *(int *)key;
3021
const int b = *(int *)memb;
3122
if (a == b)
@@ -34,16 +25,13 @@ int_comp(const void *key, const void *memb)
3425
return -1;
3526
}
3627

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) {
4129
char *ret = NULL;
4230
int i;
4331
char *line = (char *)calloc(500, sizeof(char));
4432
check_mem(line);
4533
while (fgets(line, 400, fp) != NULL) {
46-
if (strncasecmp(line, fstr, strlen(fstr)) == 0){
34+
if (strncasecmp(line, fstr, strlen(fstr)) == 0) {
4735
ret = strtok(line, delim);
4836
for (i = 0; i < nfield; i++) {
4937
ret = strtok(NULL, delim);
@@ -58,28 +46,26 @@ grep_awk(FILE *fp, const char *fstr, int nfield, const char *delim)
5846
}
5947
free(line);
6048
return NULL;
61-
error:
49+
error:
6250
return NULL;
6351
}
6452

65-
char *
66-
squeeze(char *string, const char *chars)
67-
{
53+
char *squeeze(char *string, const char *chars) {
6854
char *src = string;
6955
char *target = string;
7056
char ch;
71-
for(;*chars; chars++) {
72-
ch =*chars;
57+
for (; *chars; chars++) {
58+
ch = *chars;
7359
src = string;
7460
target = string;
75-
while(*src != '\0') {
61+
while (*src != '\0') {
7662
if (*src != ch) {
7763
*target = *src;
7864
target++;
79-
}
65+
}
8066
src++;
8167
}
82-
*target='\0';
68+
*target = '\0';
8369
}
8470
return string;
8571
}

Diff for: common.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#pragma once
22

3-
#include <stdio.h>
43
#include <errno.h>
4+
#include <stdio.h>
5+
#include <stdint.h>
56
#include <string.h>
67

7-
float percentage(unsigned long int, unsigned long int);
8+
float percentage(uint64_t, uint64_t);
89
int str_comp(const void *, const void *);
910
int int_comp(const void *, const void *);
1011
char *grep_awk(FILE *, const char *, int, const char *);

0 commit comments

Comments
 (0)