I'm writing a program where the user can input a number with an arithmetic operator, and then I find out which arithmetic operator it is and print it. For ex- 123456+123456 --> Opertor present is: '+'
I can't figure out how to identify the operator in the user input.
Here's my code:
#include<stdio.h>
#include<string.h>
char numberArray1[50];
int i=0,lengthofFirstNumber;
int inputforCalculator(){
//Variable declaration
char operator;
//Will stay here always
printf("Calc>");
//Getting input from user
gets(numberArray1);
doArithmeticOperations(numberArray1);
}
int doArithmeticOperations(){
char operator;
lengthofFirstNumber=strlen(numberArray1);
int i=0;
for(i=0;i<lengthofFirstNumber;i++){
puts(numberArray1);
//THIS PART IS NOT WORKING
if(operator == '+' ){
printf("Operator is present.");
break;
}
else{
printf("Invalid Input.");
break;
}
}
}
int main(){
char operator;
inputforCalculator(numberArray1[0],numberArray2[0]);
return 0;
}