Created
February 22, 2024 16:07
-
-
Save TheRolfFR/f1eb58e065f9bba12ceb90b6412b7187 to your computer and use it in GitHub Desktop.
Simple C rstrip implementation
This file contains 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
/** | |
* @brief Strips all the characters at the end | |
* @author TheRolf | |
* | |
* @param str target string | |
* @param chars chars to find and remove | |
*/ | |
void str_rstrip(char* str, const char* chars) | |
{ | |
size_t size_str = strlen(str); | |
if( 0U == size_str ) | |
return; | |
bool found_char = true; | |
size_t i = size_str; | |
char c_str[2]; | |
c_str[1] = '\0'; | |
do | |
{ | |
i--; | |
c_str[0] = str[i]; | |
found_char = NULL != strstr(chars, c_str); | |
if( true == found_char ) | |
{ | |
str[i] = '\0'; | |
} | |
else { /* go out */ } | |
} | |
while( (i > 0U) && (true == found_char) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment