getopt
public text v1 · immutable#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;
}