How do I get rid of leading 0's in my output?

My challenge is to convert string to integer without any string-to-integer libraries. I have a working function that converts string to integer but it doesn't eliminate the leading 0's. How would I go about doing that? Is there a library for that or a while loop that can fix this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

long stoi(const char *s)
{
long i;
i = 0;
while(*s >= '0' && *s <= '9')
{
i = i * 10 + (*s - '0');
s++;
}
return i;
}

int main() {


return 0;
}
I have a working function that converts string to integer but it doesn't eliminate the leading 0's.


Integers don't have leading zeros.
I know they don't have leading 0's which is why I'm trying to fix this.
They don't have leading zeros. Which leading zero on the front of an integer are you trying to get rid of? There aren't any, so how can you get rid of them?
I'm trying to get rid of the leading 0's in my function.
Have you tried running your function?

It turns the string 00000345 into the integer 345. The integer has no leading zeros. The function works fine.
Topic archived. No new replies allowed.