in Programming in C
273 views
0 votes
0 votes
#include <stdio.h>
int atoi(char s[]) {
        int i, n;
        n = 0;
        for(i = 0; s[i] >= '0' && s[i] <= '9'; ++i)
                n = 10*n + (s[i] - '0');
        return n;
}
int main() {
        char s[] = "jitendra";
        int number = atoi(s);
        printf("%d\n", number);
        //printf("%d\n", atoi(s));
        return 0;
}

 

in Programming in C
by
273 views

2 Comments

0
0
for(i = 0; s[i] >= '0' && s[i] <= '9'; ++i)
ascii value of alphabets is greater than ascii value of number 0
0
0

Please log in or register to answer this question.

Related questions

2 votes
2 votes
0 answers
3