#include <stdio.h>
#include <string.h>
int main()
{
char a[100] = "12+5=;45-2=;34*2=;56/3=";
char b[100] = {
0 };
char *s = strtok(a, ";");
while(s)
{
int i, j;
char c;
sscanf(s, "%d%c%d=", &i, &c, &j);
int res = 0;
switch(c)
{
case '+':
res = i + j;
break;
case '-':
res = i - j;
break;
case '*':
res = i * j;
break;
case '/':
res = i / j;
break;
default:
res = 0;
}
char tmp[10] = {
0 };
sprintf(tmp, "%s%d;", s, res);
strcat(b, tmp);
s = strtok(NULL, ";");
}
strcpy(a, b);
printf("%s\n", a);
return 0;
}
C实现将处理特定字符串
猜你喜欢
转载自blog.csdn.net/zxy131072/article/details/108493679
今日推荐
周排行