#include <stdio.h> #include <string.h> int test(char s[]){ static i=0; int n,char s[100],char a[100]; if(s[i]=='('){ i+=2; n++; } while(n){ if(s[i]>0 && s[i]<9){ a[j]=(int)(s[i] - '0') i++; j++; } if(s[i]='('){ test(s); j++; } if(s[i]=')'){ n--; } } if(a[temp]=='+'){ sun=a[0]; for(i=0;i<j;i++){ sum=sum+a[k]; } } if(a[temp]=='-'){ sun=a[0]; for(i=0;i<j;i++){ sum=sum-a[k]; } } if(a[temp]=='*'){ sun=a[0]; for(i=0;i<j;i++){ sum=sum*a[k]; } } if(a[temp]=='/'){ sun=a[0]; for(i=0;i<j;i++){ sum=sum/a[k]; } } temp = 1; i++; return sum; } int main(){ char s[100],b[100]; gets(s); for(i=0;i<strlen(s);i++){ if(s[i] != ' '){ b[j] = s[i]; j++; } } b[j]='\0'; test(b); return 0; } /* Main.c: In function 'test': Main.c:4:10: warning: type defaults to 'int' in declaration of 'i' static i=0; ^ Main.c:5:9: error: expected identifier or '(' before 'char' int n,char s[100],char a[100]; ^ Main.c:13:7: error: 'a' undeclared (first use in this function) a[j]=(int)(s[i] - '0') ^ Main.c:13:7: note: each undeclared identifier is reported only once for each function it appears in Main.c:13:9: error: 'j' undeclared (first use in this function) a[j]=(int)(s[i] - '0') ^ Main.c:14:9: error: expected ';' before 'i' i++; ^ Main.c:17:5: warning: suggest parentheses around assignment used as truth value [-Wparentheses] if(s[i]='('){ ^ Main.c:21:5: warning: suggest parentheses around assignment used as truth value [-Wparentheses] if(s[i]=')'){ ^ Main.c:28:8: error: 'temp' undeclared (first use in this function) if(a[temp]=='+'){ ^ Main.c:29:5: error: 'sun' undeclared (first use in this function) sun=a[0]; ^ Main.c:31:7: error: 'sum' undeclared (first use in this function) sum=sum+a[k]; ^ Main.c:31:17: error: 'k' undeclared (first use in this function) sum=sum+a[k]; ^ Main.c: In function 'main': Main.c:65:3: warning: 'gets' is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations] gets(s); ^ Main.c:66:7: error: 'i' undeclared (first use in this function) for(i=0;i<strlen(s);i++){ ^ Main.c:68:9: error: 'j' undeclared (first use in this function) b[j] = s[i]; ^ Main.c: In function 'test': Main.c:62:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ */ |
Double click to view unformatted code.