Hi there. I am trying to implement a very basic shell for a flat file system. Anyhow, my shell will be very simple for now. It will be an endless while loop where I prompt for input and after reading it in a string with fgets I use sscanf to break it up ( I suppose I could use a delimiter as well but since all comands are separated by spaces I guess it's okay)
and then I was thinking of how to call the appropriate function.
I thought of comparing the command with all available commands or using table with pointer (well actually I havent thought much about that yet, just that it came to me that maybe I could use funtion pointers) but I wanted to ask here first (I searched a little but couldnt find anything helping me as far aas c is concerned)
Is there any way to use a string variable to call a function
Here is what my code would like:
Code:
while(1) {
printf("prompt> ");
...
if(!fgets(line,sizeof(line),stdin)) break;
...
args = sscanf(line,"%s %s %s",cmd,arg1,arg2);
...
}