Analysis of spaces, end and head, from a C-string

I'm trying to extract the C-key value from a string into a configuration file that may have arbitrary spaces preceding and following the string. That's what I've proposed so far. It is not quite that yet. It has been some time since I started using the C language and have been spoiled by the methods of processing strings embedded in higher level languages ​​over the years.

Is it far away or am I on the right track?

char buf = "key = a value";
...

char * ptr = strstr (buf, "=");

if (ptr)
{
/ * move the ptr into the non-white character after & # 39; = & # 39; * /
while (* (++ ptr) == & # 39;);

/ * subtract the address from the end of the line to the ptr for the length of the malloc * /
int len ​​= buf + strlen (buf) - ptr;

/ * point to the first non-white character at the end of the string * /
char * ws = strrchr (ptr, "");
if (ws)
{
/ * truncates the string to the first spacing character and adjusts the length * /
* (ws) = 0x0;
len = ws - ptr;
}

char * my_key = malloc (len + 1);

if (my_key)
snprintf (my_key, len, "% s", ptr);
...