Changed darr_at to return a pointer

This commit is contained in:
2024-04-29 01:06:58 +05:30
parent 1fcdf853bd
commit 3e64d7855a
2 changed files with 4 additions and 4 deletions

View File

@@ -51,12 +51,12 @@ void darr_append_bytes(darr_t *darr, byte_t *bytes, size_t n)
darr->used += n; darr->used += n;
} }
byte_t darr_at(darr_t *darr, size_t index) byte_t *darr_at(darr_t *darr, size_t index)
{ {
if (index >= darr->used) if (index >= darr->used)
// TODO: Error (index is out of bounds) // TODO: Error (index is out of bounds)
return 0; return NULL;
return darr->data[index]; return darr->data + index;
} }
void darr_write_file(darr_t *bytes, FILE *fp) void darr_write_file(darr_t *bytes, FILE *fp)

View File

@@ -119,7 +119,7 @@ void darr_append_bytes(darr_t *darr, byte_t *b, size_t n);
@return Byte at the nth position, or 0 if n is an invalid index @return Byte at the nth position, or 0 if n is an invalid index
*/ */
byte_t darr_at(darr_t *darr, size_t n); byte_t *darr_at(darr_t *darr, size_t n);
/** /**
@brief Write the bytes of a dynamic array to a file pointer @brief Write the bytes of a dynamic array to a file pointer