i am creating a basic calculator program for a class and and stuck on the multiplication. when the third argument is * it goes all funky and give a segmentation fault. my only guess is that this is because in the shell * is a wild card.
Code:
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
int main(int argc, char *argv[]){
int a;
int b;
int c;
if (argc == 4 || (strcmp (argv[4], "dec") == 0 )){
if (strcmp (argv[2], "+") == 0){
a = atoi(argv[1]);
b = atoi(argv[3]);
c= a+b;
printf("%d\n", c);}
if (strcmp (argv[2], "-")==0){
a = atoi(argv[1]);
b = atoi(argv[3]);
c= a-b;
printf("%d\n", c);}
if (strcmp (argv[2], "*")==0){
a = atoi(argv[1]);
b = atoi(argv[3]);
c= a*b;
printf("%d\n", c);}
}
return 0;
}
our teacher warned us of this and said "Remember what * means in the shell. How do you protect it? " as a tip
how to i protect it