This is a simplified version of my code:
void calc(char *s)
{
int t = 0;
while (*s)
{
if (isdigit(*s))
t += *s - '0';
else
++s;
}
printf("t = %d\n", t);
}
int main(int argc, char* argv[])
{
calc("8+9-10+11");
return 0;
}
The problem is that the while loop works forever, although I expect it to stop after the last digit 1. And my expected result: t = 20.
source
share