So is it really seperate commands to access the microcontroller to play the audio files? It seems to me that it would be something like PlayAudioClip(offset) where offset would represent which section of audio to play.
I have included a mockup sample which I think does generally what you are trying to do. Note I do not need function pointers to implement this at all. Also, this is a quick example; if you were to implement these things pay attention to the comments and also avoid those magic numbers (aka numerical literals for array bound checking). I hope this helps you implement a better solution to your current problem.
Code:
#include <stdio.h>
#include <string.h>
//this is just an example to represent the microcontroller that would hold
//the audio files
char *AudioFiles[50]={"This is my first line of text",
"This is my second line of text",
"Why doesn't Barbie get pregnant?",
"Because Ken comes in a different box"};
//This would simulate my command to the microcontroller to play a "file"
int playAudio(int);
//This is our function to get the user input and convert to int for use
//with our switch statement. Note: There are cleaner solutions for this
//however let's keep things simple for now
int getUserInput(void);
int main(void){
//This would be our original offset
int delta = 0;
//Stores return from getUserInput()
int choice = 0;
//This is our main program loop where we sample for user input and then make
//make our decisions based on that input
while((choice=getUserInput()) != 0){
switch(choice){
case 1: //continue-plays the next line of text
if(delta<2)
delta++;
break;
case 2: //fast forward-plays 2 lines forward
if(delta<2)
delta+=2;
else if(delta<3)
delta++;
break;
case 3: //rewind
if(delta>0)
delta--;
break;
default://no valid input
printf("Command not recognized\n");
//this jumps us to the next iteration of our loop
//bypassing our playAudio function
continue;
}
//This will allow us to keep track of what the current text is
//see the definition of the function below for the reason
delta = playAudio(delta);
}
getchar();
return (0);
}
int playAudio(int offset){
//As stated before this simulates what you need to do for your microcontroller
//You don't necessarily need to understand the process behind the array because
//that is not what you are dealing with
printf("%s\n",AudioFiles[offset]);
//return our offset to our main loop. I put this in because I am unsure of how your
//microcontroller is set up. For instance, on an MP3 player this would most likely
//be the next track, aka offset + 1
return (offset);
}
int getUserInput(void){
//This stores our user input
char userInput[10];
//The printf and fgets statements can be ignored since they are not how you get
//your input.
//used to make our input a null terminated string. May or may not be required for //you
char *nullSearch=NULL;
printf("What do you want to do?");
fgets(userInput, 10, stdin);
//this just makes this a null terminated string.
if((nullSearch=strchr(userInput,'\n'))!=NULL)
*nullSearch = '\0';
//Now this is where we format our input so our main loop can process easier. Note:
//I broke this up into seperate functions assuming you had a similar input function
//for the microcontroller
if(strcmp(userInput, "exit")==0)
return 0;
else if(strcmp(userInput,"continue")==0)
return 1;
else if(strcmp(userInput, "ff")==0)
return 2;
else if(strcmp(userInput, "rw")==0)
return 3;
//return our command not found error number. Pick one.
return (42);
}
Let me know if you have any questions.