C input loop for shell
- by AustinM
So I'm working on creating a very simple C program that just preforms shell commands. This is what I have so far:
#include <stdio.h>
int main()
{
char input[30];
fputs("$ ", stdout);
fflush(stdout);
fgets(input, sizeof input, stdin);
system(input);
}
It works, but only for one command. For example if I compile and type ./cmd I get the $ prompt. If I type ls I get what I'm supposed to get. But then it exits and goes back to the regular system shell. How can I make it so after the user types a command it goes back to the "$" input.