Created
July 21, 2021 15:18
-
-
Save alsamitech/62d1db3b9ab77429fc6cb0a039d90efe to your computer and use it in GitHub Desktop.
returns position of last byte in a string or array of bytes
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(const char* const bytes, const char byte,size_t len){ | |
| while(bytes[len]!=byte&&len)len--; | |
| return len; | |
| } | |
| // returns position of the last character of a string whose length is not known. | |
| size_t get_last_char(const char* const str, const char byte){ | |
| size_t pos=0; | |
| for(size_t i=0;str[i];i++) | |
| if(str[i]==byte) pos=i; | |
| return pos; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment