Enter a multi-operand string, output the result, support only arithmetic, and support only integers.
Parsing string operations (without parentheses)
int calculatorfinal (char *str)
{
JIEGUO[100][10] for storing parsed arrays
Char *p[100], jieguo[100][10];
int result, secondnumber, i = 0, j = 0;
Char tempnumber[20], op;
for (i = 0; i <; i++) {
P[i] = Jieguo[i];
}
i = 0;
Parse the string and put it into a two-dimensional array
while (*STR) {
if (*str >= ' 0 ' && *str <= ' 9 ') {
TEMPNUMBER[J] = *str;
j + +;
}else{
TEMPNUMBER[J] = ' + ';
strcpy (P[i], tempnumber);
i++;
for (int j = 0; J <; J + +) {
TEMPNUMBER[J] = ' + ';
}
Tempnumber[0] = *str;
strcpy (P[i], tempnumber);
i++;
Tempnumber[0] = ' + ';
j = 0;
}
str++;
}
strcpy (P[i], tempnumber);
i++;
for (int j = 0; J <; J + +) {
TEMPNUMBER[J] = ' + ';
}
Tempnumber[0] = *str;
strcpy (P[i], tempnumber);
printf ("* * * * parsing string result ********\n");
for (j = 0; J < i; J + +) {
Puts (P[j]);
// }
printf ("* * * * * multiplication law ********\n");
for (int n = 0; n < i; n++) {
if (n% 2 = = 1) {
op = p[n][0];
if (op = = ' * ') {
result = Atoi (p[n-1]) * ATOI (p[n + 1]);
printf ("result =%d\n", result);
for (int m = n; m < i; m++) {
if (M = = N) {
printf ("result =%d\n", result);
sprintf (P[m-1], "%d", result);
Puts (p[m-1]);
}
To determine if this calculation is the last group, the words stop moving the array, not the words move
if (M + 2! = i) {
strcpy (P[m], p[m + 2]);
strcpy (p[m + 1], P[m + 3]);
}else if (m + 2 = = i) {
Each time an operation is performed, the array moves up and starts to detect ' * ', '/'
and reduce the array size by 2
n = 0;
I-= 2;
Break
}
}
}else if (op = = '/') {
result = Atoi (p[n-1])/atoi (P[n + 1]);
for (int m = n; m < i; m++) {
if (M = = N) {
printf ("result =%d\n", result);
sprintf (P[m-1], "%d", result);
Puts (p[m-1]);
}
To determine if this calculation is the last group, the words stop moving the array, not the words move
if (M + 2! = i) {
strcpy (P[m], p[m + 2]);
strcpy (p[m + 1], P[m + 3]);
}else if (m + 2 = = i) {
Each time an operation is performed, the array moves up and starts to detect ' * ', '/'
and reduce the array size by 2
n = 0;
I-= 2;
Break
}
}
}
}
}
printf ("* * * * * * multiplication----results ********\n");
for (j = 0; J < i; J + +) {
Puts (P[j]);
// }
printf ("* * * * Add subtraction----results ********\n");
for (int n = 0; n < i; n++) {
if (n% 2 = = 1) {
op = p[n][0];
if (op = = ' + ') {
result = Atoi (p[n-1]) + atoi (p[n + 1]);
printf ("result =%d\n", result);
for (int m = n; m < i; m++) {
if (M = = N) {
printf ("result =%d\n", result);
sprintf (P[m-1], "%d", result);
Puts (p[m-1]);
}
To determine if this calculation is the last group, the words stop moving the array, not the words move
if (M + 2! = i) {
strcpy (P[m], p[m + 2]);
strcpy (p[m + 1], P[m + 3]);
}else if (m + 2 = = i) {
Each time an operation is performed, the array moves up and starts to detect ' * ', '/'
and reduce the array size by 2
n = 0;
I-= 2;
Break
}
}
}else if (op = = '-') {
result = Atoi (p[n-1])-atoi (P[n + 1]);
for (int m = n; m < i; m++) {
if (M = = N) {
printf ("result =%d\n", result);
sprintf (P[m-1], "%d", result);
Puts (p[m-1]);
}
To determine if this calculation is the last group, the words stop moving the array, not the words move
if (M + 2! = i) {
strcpy (P[m], p[m + 2]);
strcpy (p[m + 1], P[m + 3]);
}else if (m + 2 = = i) {
Each time an operation is performed, the array moves up and starts to detect ' * ', '/'
and reduce the array size by 2
n = 0;
I-= 2;
Break
}
}
}
}
}
return result;
}
C language multiple operation string, output (not easy Ah, adjusted for 1 hours, just adjust it out ....) I hope the gods have a better way of pointing twos.