user-0 提问: 求大神帮忙把程序改一下错误（用C语言设计一个简单的计算器）进行加减乘除，可带括号，不限定运算式的输入长度，多加些注释

回复:
user: user-1
content: 初步看一下，你的程序几乎都是函数名拼写错误，变量未定义等简单的语法错误，我觉得你应该没有学会借助输出窗口的信息来修正程序，学着看一下，能迅速定位到你的语法错误，至少保证程序能编译过了再发上来吧

user: user-2
content: 同意沙发说的，代码格式太差，插入代码选择C/C++

user: user-3
content: C版内人才济济，楼主何不悬赏求程序涅。 谁的代码最短，功能最好，你给谁买一个4TB移动硬盘。 如果不这样，谁能保证赵四老湿能出来解决这样的问题。

user: user-0
content: 这是我复制过来的，需要怎么改代码格式啊，求指导  #include<stdio.h>  #include<string.h>  #include<stdlib.h>  int deal(int op1,int op2,char op) //运算  {  switch(op)  {  case '+': op1 += op2; break;  case '-': op1 -= op2; break;  case '*': op1 *= op2; break;  case '/': op1 /= op2; break;  case '^':  {  int temp = op2;  for(int i = 1; i < op2 - 1; i++)  op1 *= temp;  break;  }  }  return op1;  }  char *replace(char *source, char *sub, char *rep) //字符串替换  {  char *result;  char *pc1, *pc2, *pc3;  int isource, isub, irep;  isub = strlen(sub);  irep = strlen(rep);  isource = strlen(source);  if(NULL == *sub)  return strdup(source);  result = (char *)malloc(( (irep > isub) ? (float)strlen(source) / isub* irep+ 1:isource ) * sizeof(char));  pc1 = result;  while(*source != NULL)  {  pc2 = source;  pc3 = sub;  while(*pc2 == *pc3 && *pc3 != NULL && *pc2 != NULL)  pc2++, pc3++;  if(NULL == *pc3)  {  pc3 = rep;   while(*pc3 != NULL)  *pc1++ = *pc3++;  pc2--;  source = pc2;  }  else  *pc1++ = *source;  source++;  }  *pc1 = NULL;  return result;  }   int main()  {  char s[1000],op1[100],op2[100],*p,*temp,*back;  scanf("%s",&s);  temp = s;  back = s;  int pos = -1;  int fin,oper1,oper2,tmp, size;  char op;  while(1)  {  size = (int)strlen(temp);  for(int i = 0; i < size; i++,temp++)  {  if( *temp == '(')  {  p = (temp + 1);  pos =(i + 1); //找出最后一个(的位置  }  }  int k = 0;  if(pos != -1)  {  temp = back;  tmp = pos;  while(*p != ')')  {  p++;  tmp++;  if( *p == '*' || *p == '/')  {  tmp--;  for(;(temp[tmp] >= '0' && temp[tmp] <= '9') || temp[tmp] == '.';)  {  tmp--;  break;  }  }  else  continue;  }  if(tmp != pos && *p != ')')  {  pos = ++tmp;  }  int start = pos;  while( temp[pos] >= '0' && temp[pos] <= '9')  {  op1[k] = temp[pos];  pos++;  k++;  }  op1[k] = '\0';  while((temp[pos] >= '0' && temp[pos] <= '9') || temp[pos] == '.')  pos++;  op = temp[pos];  oper1 = atoi(op1);  pos++;  k = 0;  while( temp[pos] >= '0' && temp[pos] <= '9')  {  op2[k] = temp[pos];  pos++;  k++;  }  op2[k] = '\0';  while((temp[pos] >= '0' && temp[pos] <= '9') || temp[pos] == '.')  pos++;  oper2 = atoi(op2);  int end;  if( temp[pos] != ')')  end = --pos;  else  {  if(temp[start-1] == '(')  {  end = pos;  start--;  }  }  char rep[100];  k = 0;  for(; start <= end; start++,k++)  {  rep[k] = temp[start];  }  rep[k] = '\0';  fin = deal(oper1,oper2,op);  char final[100];  itoa(fin,final,10);  temp = replace(temp,rep,final);  back = temp;  pos = -1;  p = temp;  k = 0;  *rep = NULL;  *final = NULL;  printf("%s\n",replace(temp,rep,final));  }  else  {  temp = back;  p = temp;  tmp = pos;  while(*p != '\0')  {  p++;  tmp++;  if( *p == '*' || *p == '/')  {  tmp--;  for(;(temp[tmp] >= '0' && temp[tmp] <= '9') || temp[tmp] == '.';)  {  tmp--;  break;  }  }  else  continue;  break;  }  if(tmp != pos && tmp != (int)strlen(temp)-1)  {  pos = ++tmp;  }  else  pos = 0;  int start = pos;  while( temp[pos] >= '0' && temp[pos] <= '9')  {  op1[k] = temp[pos];  pos++;  k++;  }  while((temp[pos] >= '0' && temp[pos] <= '9') || temp[pos] == '.')  pos++;  op1[k] = '\0';  op = temp[pos];  oper1 = atoi(op1);  pos++;  k = 0;  while( temp[pos] >= '0' && temp[pos] <= '9')  {  op2[k] = temp[pos];  pos++;  k++;  }  op2[k] = '\0';  while((temp[pos] >= '0' && temp[pos] <= '9') || temp[pos] == '.')  {  pos++;  if(pos >= (int)strlen(temp))  break;  }  oper2 = atoi(op2);  int end = --pos;  char rep[100] = {'\0'};  k = 0;  for(; start <= end; start++)  {  rep[k] = temp[start];  k++;  }  fin = deal(oper1,oper2,op);  char final[100];  itoa(fin,final,10);  temp = replace(temp,rep,final);  back = temp;  for(k = 0; k < (int)strlen(temp); k++)  {  if(temp[k] < '0' || temp[k] > '9' && temp[k] != '.')  break;  }  if(k == (int)strlen(temp))  break;  pos = -1;  p = temp;  k = 0;  printf("%s\n", temp);  }  }  printf("%d\n",fin);  return 0;  }

user: user-0
content: 我就是按着网上写着的照搬的，也许中间有些没弄对，，，我只是略懂皮毛，上课不好好听啊，唉，，，

user: user-0
content: 好多人都说代码格式太差，我是菜鸟刚入门也不怎么会弄，求指导一下了，老是催着考试要看得，，也就是临阵磨枪网上找的，，，

user: user-4
content: 太长了。。。。。。

user: user-5
content: 建议自己好好看吧，一步步看，想明白这样写的原因， 代码格式太差，要不楼主按代码格式从新发一下吧，要不又有几个人愿意看