Programming Algorithms Question:
Write a function that finds the last instance of a character in a string

Answer:
char *lastchar(char *String, char ch)
{
char *pStr = NULL;
// traverse the entire string
while( * String ++ != NULL )
{
if( *String == ch )
pStr = String;
}
return pStr;
}
{
char *pStr = NULL;
// traverse the entire string
while( * String ++ != NULL )
{
if( *String == ch )
pStr = String;
}
return pStr;
}
Previous Question | Next Question |
What is comp.ai.genetic all about? | Return Nth the node from the end of the linked list in one pass. |