Hi there,
I'm making a simple shell program in pico using Unix.
I was given most the code from a tutor and added bits to it, it's supposed to go to a prompt allowing user to type but instead it does nothing.
No errors are shown.
Btw: i use gcc -o shell shell.c to try to compile and run it.
Hopefully someone could read what i have below or try it for themselves and point me in the right direction, Having the prompt come up would make thing alot easier for me!
Thanks in advance.
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
main()
{
char buf[1024];
char *args[64];
for(;;)
{
printf("Command:");
if(fgets(buf, 100, stdin) == NULL)
{
printf("\n");
exit(0);
}
parse(buf,args);
execute(args);
}
}
void help()
}
printf("oh no");
printf("oh yes");
}
parse(buf,args)
char *buf;
char **args;
{
while(*buf != 0)
{
while((buf*buf == ' ') || (*buf == '\t'))
*buf++ = 0;
*args++ = buf;
while((*buf!= 0) && (*buf != ' ') && (*buf != '\t'))
buf++;
}
*args = NULL;
}
execute(args)
char **args;
{
int pid,status;
if ((pid = fork())<0)
{
perror("fork");
exit(1);
}
if (pid == 0)
{
if(strcmp(*args,"help")==0)
{
help();
}
else
{
execvp(*args,args);
}
perror(*args);
exit(1);
}
while (wait(&status) !=pid)
/*empty*/;
}