I need some help getting started on parsing elements on a command line with a shell. I have to take different elements separated by empty spaces, single quotes, and,double quotes and turn them into tokens. Any advice on what function or methods I can use?
This is my code so far:
#include <stdio.h> //printf
#include <unistd.h> //isatty
#include <string.h> //strlen
int main(int argc, char **argv[]){
int MaxLength = 1024; //size of buffer
char buffer[MaxLength]; //bufer
bzero(buffer,sizeof(buffer)); //zeros out the buffer
char *command; // character pointer of strings
int inloop =1;
/* part 1 isatty */
if (isatty(0))
{
while(inloop ==1) // check if the standard input is from terminal
{
printf("$");
command = fgets(buffer,sizeof(buffer),stdin); //fgets(string of char pointer,size of,input from where
//check for empty space
//check for ''
//check for ""
//check for |
if(strcmp(command,"exit\n")==0)
inloop =0;
}
}
else
printf("the standard input is NOT from a terminal\n");
return 0;
}