#include<stdio.h>
int isNumericChar(char s){
return ((s > '0' && s <'9') ? 1:0);
}
int my_atoi(char* s){
int res = 0;
int sign = 1;
while(*s != '\0'){
if(isNumericChar(*s) == 0){
return 0;
}
if(*s == '-'){
sign = -1;
s++;
}
res = ((res * 10) + (*s - '0'));
s++;
}
return (res*sign);
}
int main(){
char *s = "924";
printf("\natoi : %d\n",my_atoi(s));
return 0;
}
How to convert the strings into integers for 0 and 9 entered ? Is there a way to convert the hexadecimal entered to be printed in hexadecimal representation ?