Store a char pointer from terminal input in C -
i'm trying create simple calculator input terminal. supposed work this:
./main.c 1 + 3 1 + 3 = 4
it simple code per se, have problem terminal input. have read lot here @ stackexchange terminal input error while compiling:
error: assignment incompatible pointer type [-werror=incompatible-pointer-types]
i not know why. have tried lot of different ways not work. here code, want know how store 1, + , 3 in example above. code post here example how can store "difficult" operation, in case + operator.
#include<stdio.h> int main(int argc, char *argv[]) { char operator; int *operatorp; operatorp = &operator; operatorp = argv[2]; printf("%c\n",operator); return 0; }
it not correct, trying convert int * char.
just
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char **argv) { int nbr1 = atoi(argv[1]); char operator = argv[2][0]; int nbr2 = atoi(argv[3]); int result = 0; if (operator == '+') result = nbr1 + nbr2; printf("%d\n", result); }
Comments
Post a Comment