I have a function which accepts some values as char array[] parameters.
These values are separated with semicolons (';').
For example: "hello;dear;John"
So I’m trying to figure out a way by using strtok to delete the last string, which is "John" after the last semicolon.
int remove(char lastName[]){
}
*To be more specific
I have created this function which removes values separated by semicolons:
int remove(char variable_Name[]){
char *value_toRemove = getenv(variable_Name);
char last_semicolon[] = ";";
char *result = NULL;
result = strtok( value_toRemove, last_semicolon );
while( result != NULL ) {
result = strtok( NULL, last_semicolon );
}
return NULL;
}
But the function deletes everything after it finds a semicolon.
strrchrwill find the last occurance of the character.Sor if you don’t mind modifyint the original string then it should be as simple as
Man Page here