All pastes #43413 Raw Edit

getopt

public text v1 · immutable
#43413 ·published 2006-02-27 20:36 UTC
rendered paste body
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>

int main(int argc, char **argv)
{
   int c, ans;

   while((c = getopt(argc, argv, "asmdo:p:")) != -1)
   {
      switch(c)
      {
         case 'a':
            ans = optarg[1] + optarg[2];
         case 's':
            ans = optarg[1] - optarg[2];
         case 'm':
            ans = optarg[1] * optarg[2];
         case 'd':
            ans = optarg[1] / optarg[2];
      }
      printf("The answer is %d\n", ans);
   }
   return 0;
}