How to write a function that finds the last instance of a character in a string

char * lastchar(char * String, char ch) {
  char * pStr = NULL;

  // traverse the entire string

  while ( * String++ != NULL) {
    if ( * String == ch)
      pStr = String;

  return pStr;

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest updates on your inbox

Be the first to receive the latest updates from Codesdoc by signing up to our email subscription.