remove stderr printing
This commit is contained in:
		| @@ -13,7 +13,7 @@ and subsequently the size of `substrings`. | ||||
| If no substrings are found, `substrings` will not be allocated and left set to `NULL`, `num_substrings` will be `0`, and | ||||
| the function will return `0`. | ||||
|  | ||||
| Returns 0 if the function is successful, returns a non-zero value and prints to `stderr` if there is an error. | ||||
| Returns 0 if the function is successful. Returns a non-zero value if there is an error. | ||||
|  | ||||
| ```c | ||||
| int find_substrings(const char* haystack, const char* needle, size_t *num_substrings, size_t **substrings); | ||||
| @@ -34,7 +34,7 @@ free(subs); | ||||
| ### substr | ||||
|  | ||||
| Extracts a substring at a specific index and length. This function returns a copy of the substring in a heap allocated | ||||
| buffer that the user is responsible for freeing. Returns `NULL` and prints to `stderr` if there is an error. | ||||
| buffer that the user is responsible for freeing. Returns `NULL` if there is an error. | ||||
|  | ||||
| ```c | ||||
| const char* substr(const char* str, size_t idx, size_t len); | ||||
|   | ||||
| @@ -12,5 +12,6 @@ nav: | ||||
|     - 'Math': 'math.md' | ||||
|     - 'Set': 'set.md' | ||||
|     - 'Stack': 'stack.md' | ||||
|     - 'String': 'string.md' | ||||
|     - 'Utility': 'utility.md' | ||||
|     - 'Vector': 'vector.md' | ||||
|   | ||||
| @@ -1,12 +1,10 @@ | ||||
| #include <string.h> | ||||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
|  | ||||
| #include "lfstring.h" | ||||
|  | ||||
| int find_substrings(const char* haystack, const char* needle, size_t *num_substrings, size_t **substrings) { | ||||
|     if (*substrings != NULL) { | ||||
|         fprintf(stderr, "substrings was not NULL in find_substring\n"); | ||||
|         return 1; | ||||
|     } | ||||
|  | ||||
| @@ -29,7 +27,6 @@ int find_substrings(const char* haystack, const char* needle, size_t *num_substr | ||||
|  | ||||
|     *substrings = malloc(sizeof(size_t) * *num_substrings); | ||||
|     if (*substrings == NULL) { | ||||
|         fprintf(stderr, "Memory allocation failed in find_substrings\n"); | ||||
|         return -1; | ||||
|     } | ||||
|  | ||||
| @@ -46,13 +43,11 @@ int find_substrings(const char* haystack, const char* needle, size_t *num_substr | ||||
| const char* substr(const char* str, size_t idx, size_t len) { | ||||
|    size_t sz_str = strlen(str); | ||||
|    if (sz_str < len || idx + len > sz_str) { | ||||
|        fprintf(stderr, "Improper size arguments in substr\n"); | ||||
|        return NULL; | ||||
|    } | ||||
|  | ||||
|    char *substr = malloc(sizeof(char) * len + 1); | ||||
|    if (substr == NULL) { | ||||
|        fprintf(stderr, "Memory allocation error in substr\n"); | ||||
|        return NULL; | ||||
|    } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user