C program to convert string to integer without using atoi function
#include <stdio.h>
#include <string.h>
long long mypow(int m){
long long di = 1;
if(m == 0){
return 1;
}
for(int i = 0; i<m; i++){
di = di * 10;
}
return di;
}
long long toint64(const char *src){
long long n = 0;
int m = 0;
int len = strlen(src) - 1;
while(len + 1){
if((src[len] <= '9') && (src[len] >= '0')){
n += (src[len] -'0') * (mypow(m));
m++;
}
len--;
}
return n;
}
int main()
{
char *a = "2019-12-04 00:00;";
char *b = "1a2b3c4d5**678U 9";
printf("%I64d\n",toint64(a));
printf("%I64d\n",toint64(b));
return 0;
}