All I want is a user input for the array foo and print op, left, and right from it.
I tried adding the following code, but can't get the same result.
Instead of writing char foo [29] = "1021+2551";
I wrote:
int i;
printf("Enter the number and opperator");
for(i=0; i<1; i++) // I used i < 1 b/c I want to get only one line input
{
scanf("%c", foo[i]);
}
void main(){
int index;
char foo[29] = "1021+2551";
int len = strlen(foo);
for (int i=0; i < len; i++)
{
if(foo[i] == '+' || foo[i] == '-' || foo[i] == '*' || foo[i] == '/' || foo[i] == '%'){
char op = foo[i];
printf("%c", op);
index = i;
}
}
char left;
for(int j=0; j < index; j++){
left = printf("%c",foo[j]);
}
char right;
for(int k=index + 1; k < len; k++){
right = printf("%c",foo[k]);
}
}
If I enter 100+200 in the user input the result should be
+100200