C advice - Mplayer slave mode

Hi everyone,

Thank you for your time to read this. I have a little question about
how to write a C program to control mplayer in slave mode.

I have the file mp3 file I want to play stored in a structure as a


I start MPlayer using popen().

mplayer_s_pointer = popen("mplayer -slave -idle","w"); //Start MPlayer

I could use;

mplayer_s_pointer = popen("mplayer -slave -idle /xxx.mp3","w"); //
Start MPlayer

But I want to change the audio file to play dependant on inputs, hence
I need to call the mp3 to play from a structure.

I've tried;

intreturn = write(mplayer_s_pointer, record[i].media, 8);
fprintf(mplayer_s_pointer, "/%s\n", record[i].media);

but none seem to work. Can anyone advise me how I would/could pass
mplayer a string from a structure?

Thank you again for your time,


I've also read that:

When run with the -slave option MPlayer will read commands separated
by a newline (\n) from stdin