Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/superwhiskers/nom
crunch but the letter c
https://github.com/superwhiskers/nom
Last synced: 12 days ago
JSON representation
crunch but the letter c
- Host: GitHub
- URL: https://github.com/superwhiskers/nom
- Owner: superwhiskers
- License: mpl-2.0
- Created: 2019-06-19T06:13:42.000Z (over 5 years ago)
- Default Branch: canon
- Last Pushed: 2023-01-14T02:58:49.000Z (almost 2 years ago)
- Last Synced: 2024-11-07T09:45:30.697Z (2 months ago)
- Language: C
- Size: 59.6 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# nom
crunch but the letter c
## example
```c
#include
#include "nom.h"void print_char_array(int size, unsigned char *arr) {
printf("[");
for (int i = 0; i < size; i++) {printf("%d", arr[i]);
if (i != size-1) {printf(" ");
}
}
printf("]");}
int main() {
// create a container for the buffer
NomBuffer *buf = malloc(sizeof(NomBuffer));// creates a new buffer with four zeroes
nom_buffer_new(buf, 4);// write the byte `0x01` to the first offset, and move the offset forward one
nom_buffer_writebytesnext(buf, 1, (unsigned char[]){0x01});// write the byte `0x01` to the second offset, and move the offset forward one
nom_buffer_writebytesnext(buf, 1, (unsigned char[]){0x01});// seek the offset back one
nom_buffer_seekbyte(buf, -1, 1);
// write the bytes `0x02` and `0x03` to the second and third offsets, respectively
nom_buffer_writebytesnext(buf, 2, (unsigned char[]){0x02, 0x03});// write the byte `0x04` to offset `0x03`
nom_buffer_writebytes(buf, 0x03, 1, (unsigned char[]){0x04});// output the buffer's contents to the console
print_char_array(buf->cap, buf->buf);// free the used memory
nom_buffer_destroy(buf);return 0;
}
```