-2

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;
} 
dspaces1
  • 193
  • 1
  • 3
  • 15
  • `` provides 22 functions, more than half of which are for scanning and comparing. It's not a lot of documentation to read... – Notlikethat Feb 19 '14 at 23:28
  • Did you try to read this post? This deals with something similar http://stackoverflow.com/questions/9642732/parsing-command-line-arguments – user376507 Feb 19 '14 at 23:51

1 Answers1

0

You may need getopt. This is GNU compatible variant.

triclosan
  • 5,578
  • 6
  • 26
  • 50