Created
July 21, 2021 20:49
-
-
Save alsamitech/a379ab0e83fd546f7ff27856c9d28c47 to your computer and use it in GitHub Desktop.
get_last_ex - get_last but throws excpetions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // returns position of the last byte in an array or string whose length is known. | |
| size_t get_last_byte_ex(const char* const bytes, const char byte,size_t len, _Bool* const exists){ | |
| while(bytes[len]!=byte){ | |
| if(!len){ | |
| *exists=0; | |
| return 0; | |
| } | |
| len--; | |
| } | |
| *exists=1; | |
| return len; | |
| } | |
| // returns position of the last character of a string whose length is not known. | |
| size_t get_last_char_ex(const char* const str, const char byte, _Bool* const exists){ | |
| size_t pos=0; | |
| for(size_t i=0;str[i];i++) | |
| if(str[i]==byte) pos=i; | |
| if(!pos) *exists=0; | |
| else*exists=1; | |
| return pos; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment