Serial Parsing: Working for number but not for chars

Hey guys! Simple question here! I'm getting data from serial as follows

void loop() {
  
  while(Serial.available() > 0) {  
    char c=Serial.read();  
    
    if(sofar<MAX_BUF-1) buffer[sofar++]=c;  // store it
    if(c=='\n') {                                         // entire message received
	  buffer[sofar]=0;                             // end the buffer so string functions work right

         //Doing Parsing here!
}}}

For parsing all numbers after a certain letter, say "X" (until reaches next space), this works beatifully: (If I send X10 and it returns me 10)

 float parsenumber(char letter,float val) {
  char *ptr=buffer;
  while(ptr && *ptr && ptr<buffer+sofar) {
    if(*ptr==letter) {
      return atof(ptr+1);
      }
    ptr=strchr(ptr,' ')+1;
  }
  
  return val;
}

But, now, how do I do the same to get a letter? Lets say I send XY, i would expect "Y". I guess it would be the same but with "chars" right? The following keeps returning me a "S":

char parseletter(char code,char val) {

	char *ptr=buffer;

	while(ptr && *ptr && ptr<buffer+sofar) {

		if(*ptr==code) {
			return char(*ptr+1);    //Am I returning the char correctly here???????
		}
		ptr=strchr(ptr,' ')+1;
	}
	return val;
}

I´m pretty sure my mistake is in how i´m trying to return the value...but can´t figure it out!

Why do you need to screw around with pointers in parseletter()?

char parseletter(char code,char val)
{
   byte b=0;
   while(b<sofar)
   {
      if(buffer[b] == code)
        return buffer[b+1];
      b++;
   }
   return val;
}

Maybe have a look at the parse example in Serial Input Basics

...R

Why do you need to screw around with pointers in parseletter()?

Thanks Paul, your code works flawlessly!

I was messing around with pointers for didactic purposes... I know that it is not the best way to go but still bugs me what I was doing wrong, since I could make it work with numbers!

Maybe have a look at the parse example in Serial Input Basics

Indeed an awesome Tutorial and I should say I was reading the thread #72 (the one with parsing) by the time I came here to check on the replies! great job btw!