I'm getting Spotify's window title for my Now Playing plugin with function:
GetWindowText(spotify_window_handle, title, title_length)
but output contain Replacement character uFFFD.
Ex. Spotify - Killswitch Engage ? One Last Sunset
How to replace ? with - in C?
Below full code:
char* spotify_title(int window_handle)
{
int title_length = GetWindowTextLength(window_handle);
if(title_length != 0)
{
char* title;
title = (char*)malloc((++title_length) * sizeof *title );
if(title != NULL)
{
GetWindowText(window_handle, title, title_length);
if(strcmp(title, "Spotify") != 0)
{
return title;
}
else
{
return "Spotify is not playing anything right now. Type !botnext command to restart playback.";
}
}
else
{
printf("PLUGIN: Unable to allocate memory for title
");
}
free(title);
}
else
{
printf("PLUGIN: Unable to get Spotify window title
");
}
}
// End of Spotify get title function
See Question&Answers more detail:os