Skip to main content

CommandLine in C Programming



#include<Stdio.h>
#include<string.h>
#include<stdlib.h>

int main(int argc, char *argv[])
{
    char *operator;
    int a,b;
    operation = argv[1];
    a = atoi(argv[2]);
    b = atoi(argv[3]);
    if(strcmp(operation, "add")==0)
    {
        printf("%d",a+b);
    }
         else if(strcmp(operation, "sub")==0)
    {
        printf("%d",a-b);
    }
        else if(strcmp(operation, "mul")==0)
    {
        printf("%d",a*b);
    }  
        else if(strcmp(operation, "div")==0)
    {
        printf("%d",a/b);
    }
    return 0;
}

Comments