I need to assign numbers in different variables (from string) and by using the letters do some operations on the numbers.
m -15 3 c 1 -15 1 11 m 2 2 r 30 m -11 40 l 60 m 1 5 d<br>
-every letter represents a action
-every number is the measurements
-user gives this input, and i don't know how to assign separately, or after assign the input as a string i couldn't separate.
(also couldn't find the right phrase to search)
I have tried like this:
while(input[i]!='\0'){
switch(input[i]){
i++;
case 'm': a=input[i]*input[i+2];
printf("%d",a);
i+=6; // going for the next letter if i assume that
// user gave the input with single spaces between every integer or letter
break;
case 'c': ............................
i+=4;
printf("\n----CASE C");
break;
default: printf("\nDEFAULT"); return 0;
}
}
something like this, but truth user might give without spaces or with many spaces and its not certain that how many input user will give, so is there any way to extract integers? (letters also important and integer can be negative)