#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char buf[] = "23.3+29.96+22.5+31.7+27.08+24.78+64.7+23.3+21.65+11.9+21.65+22.83+22.19+21.45";
char *temp = strtok(buf, "+");
double sum = 0;
while (temp)
{
printf("%s\n", temp);
double temp1 = atof(temp); // 将字符串转换为浮点数
sum += temp1;
temp = strtok(NULL, "+");
}
printf("Sum: %.2f\n", sum);
return 0;
}
用来计算打车费