https://github.com/jwerle/chfreq.c
Compute character frequency in a string
https://github.com/jwerle/chfreq.c
Last synced: 11 months ago
JSON representation
Compute character frequency in a string
- Host: GitHub
- URL: https://github.com/jwerle/chfreq.c
- Owner: jwerle
- License: mit
- Created: 2014-05-05T20:09:25.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-12-15T19:14:59.000Z (over 11 years ago)
- Last Synced: 2025-04-30T16:50:02.654Z (about 1 year ago)
- Language: C
- Size: 166 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
chfreq.c
========
Compute character frequency in a string
## install
[clib](https://github.com/clibs/clib):
```sh
$ clib install jwerle/chfreq.c
```
source:
```sh
$ git clone git@github.com:jwerle/chfreq.c.git
$ cd chfreq.c
$ make
$ make install
```
## example
```c
#include
#include
#include
#include "chfreq.h"
int
main (void) {
char *str = "aabbcc";
uint32_t freq** = chfreq(str);
printf("%c %d\n", freq[0][0], freq[0][1]);
printf("%c %d\n", freq[1][0], freq[1][1]);
printf("%c %d\n", freq[2][0], freq[2][1]);
return 0;
}
```
...yields:
```
a 2
b 2
c 2
```
With the command line utility:
```sh
$ echo -n aabbcc | chfreq
a | 2
b | 2
c | 2
```
```sh
$ echo -n 'kinkajous are awesome !'| chfreq
k | 2
i | 1
n | 1
a | 3
j | 1
o | 2
u | 1
s | 2
| 3
r | 1
e | 3
w | 1
m | 1
! | 1
```
```sh
$ echo -n werle | chfreq -f '%c(%d)'
w(1)
e(2)
r(1)
l(1)
```
## api
```c
uint32_t **
chfreq (const char *src);
```
Returns an array of `uint32_t' type arrays who's character is the first index
and the occurence is the second index.
**example structure:**
```c
uint32_t mat[2][2] = {
{'a', 2},
NULL
}
```
## license
MIT