#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
int main(int argc , char *argv[])
{
int n,i,sum=0, pr=1;
int a,b;
while((n=getopt(argc,argv,":if:::l::r"))!=-1)
{
switch(n)
{
case 'i' :
case 'r' : printf("\n option %c",n);
break;
case 'f' :// printf("\n filename %s",optarg);
a=optind;
for(;optind<a+3;optind++)
{
i=atoi(argv[optind]);
sum=sum+i;
}
printf(" \n sum of the two no : %d ",sum);
break;
case 'l' : b=optind;
for(;optind<b+2;optind++)
{
i=atoi(argv[optind]);
pr=pr*i;
}
printf(" \n Product of the two no : %d ",pr);
break;
case '?' : printf("\n unknown option %c",optopt);
break;
case ':' : printf("\n argument needed : ");
break;
}
}
for(;optind<argc;optind++)
{
printf(" \n arguments : %s ",argv[optind]);
}
return 0;
}
No comments:
Post a Comment