fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  5.  
  6.  
  7. int cal(char a[]){
  8. int i=0,num=0,;
  9. int result=0;
  10. char token='0';
  11.  
  12. while(a[i]!='\0'){
  13. if(a[i]>'9' || a[i]<'0'){
  14. token=a[i];
  15. i++;
  16. continue;
  17. }
  18.  
  19. num=0;
  20. while(a[i]<='9' && a[i]>='0'){
  21. num=num*10+(a[i]-'0');
  22. i++;
  23. }
  24.  
  25. switch(token){
  26. case '*':
  27. result*=num;
  28. break;
  29. case '/':
  30. result/=num;
  31. break;
  32. case '+':
  33. result+=num;
  34. break;
  35. case '-':
  36. result-=num;
  37. break;
  38.  
  39. default:
  40. result=num;
  41. }
  42. }
  43.  
  44. return result;
  45. }
  46.  
  47. int main(int argc, char *argv[]) {
  48. int sum;
  49. char s[25];
  50.  
  51. puts("請輸入字串:");
  52. gets(s);
  53. printf("輸出的字串為\n");
  54. printf("%s \n",s);
  55. sum=cal(s);
  56. printf("輸出結果\n");
  57. printf("%d",sum);
  58.  
  59. return 0;
  60. }
  61.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
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
Standard output is empty