#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int cal( char a[ ] ) {
int i= 0 , num= 0 ,;
int result= 0 ;
char token= '0' ;
while ( a[ i] != '\0 ' ) {
if ( a[ i] > '9' || a[ i] < '0' ) {
token= a[ i] ;
i++;
continue ;
}
num= 0 ;
while ( a[ i] <= '9' && a[ i] >= '0' ) {
num= num* 10 + ( a[ i] - '0' ) ;
i++;
}
switch ( token) {
case '*' :
result*= num;
break ;
case '/' :
result/= num;
break ;
case '+' :
result+= num;
break ;
case '-' :
result-= num;
break ;
default :
result= num;
}
}
return result;
}
int main( int argc, char * argv[ ] ) {
int sum;
char s[ 25 ] ;
sum= cal( s) ;
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KCi8qIHJ1biB0aGlzIHByb2dyYW0gdXNpbmcgdGhlIGNvbnNvbGUgcGF1c2VyIG9yIGFkZCB5b3VyIG93biBnZXRjaCwgc3lzdGVtKCJwYXVzZSIpIG9yIGlucHV0IGxvb3AgKi8KCgppbnQgY2FsKGNoYXIgYVtdKXsKCWludCBpPTAsbnVtPTAsOwoJaW50IHJlc3VsdD0wOwoJY2hhciB0b2tlbj0nMCc7CgkKCXdoaWxlKGFbaV0hPSdcMCcpewoJCWlmKGFbaV0+JzknIHx8IGFbaV08JzAnKXsKCQkJCXRva2VuPWFbaV07CgkJCQlpKys7CgkJCQljb250aW51ZTsKCQl9CgkJCgkJbnVtPTA7CgkJd2hpbGUoYVtpXTw9JzknICYmIGFbaV0+PScwJyl7CgkJCW51bT1udW0qMTArKGFbaV0tJzAnKTsKCQkJaSsrOwoJCX0KCQkKCQlzd2l0Y2godG9rZW4pewoJCQljYXNlICcqJzoKCQkJCXJlc3VsdCo9bnVtOwoJCQkJYnJlYWs7CgkJCWNhc2UgJy8nOgoJCQkJcmVzdWx0Lz1udW07CgkJCQlicmVhazsKCQkJY2FzZSAnKyc6CgkJCQlyZXN1bHQrPW51bTsKCQkJCWJyZWFrOwoJCQljYXNlICctJzoKCQkJCXJlc3VsdC09bnVtOwoJCQkJYnJlYWs7CgkJCQkKCQkJZGVmYXVsdDoKCQkJCXJlc3VsdD1udW07CgkJfQoJfQoJCglyZXR1cm4gcmVzdWx0Owp9CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqYXJndltdKSB7CglpbnQgc3VtOwoJY2hhciBzWzI1XTsKCQoJcHV0cygi6KuL6Ly45YWl5a2X5Liy77yaIik7CiAgICBnZXRzKHMpOwogICAgcHJpbnRmKCLovLjlh7rnmoTlrZfkuLLngrpcbiIpOwogICAgcHJpbnRmKCIlcyBcbiIscyk7CglzdW09Y2FsKHMpOwoJcHJpbnRmKCLovLjlh7rntZDmnpxcbiIpOwoJcHJpbnRmKCIlZCIsc3VtKTsKCQoJcmV0dXJuIDA7Cn0K
compilation info
prog.c: In function 'cal':
prog.c:8:16: error: expected identifier or '(' before ';' token
int i=0,num=0,;
^
prog.c: In function 'main':
prog.c:52:5: warning: implicit declaration of function 'gets' [-Wimplicit-function-declaration]
gets(s);
^
stdout