This issue I feel is more my understanding of pointers but here goes. I am suppose to create a system program in C that performs calculations as such math operator value1 value2. Example math + 1 2. This would produce 3 on the screen. I am having troubles comparing or summing the numbers. Here is what I have so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main( int ac, char* args[] )
{
int total;
if (strcmp(*++args,"+") == 0)
{
}
printf("Total= ", value1);
if (strcmp(*args,"x") == 0)
printf("multiply");
if (strcmp(*args,"%") == 0)
printf("modulus");
if (strcmp(*args,"/") == 0)
printf("divide");
return 0;
}
I can do a string compare to get the operator but am having a hard time adding the two values. I have tried:
int value1=atoi(*++args);
Any help would be appreciated.
switchstatement might help out, indentation is your friend). Best of luck!args, and b) if I absolutely had to incrementargs, increment it after the text has succeeded:if (strcmp(*args), ..) {args++; .. }. What inspiredargs++instead of using an index variable?