Code: Select all
unsigned int str2num(char *str){
unsigned int num=0,digit=0;
while (*str!=0){
num=num+((*str-48)*upwr(10,digit)); //upwr is unsigned power and works
digit++;str++;
}
return num;
}
Code: Select all
unsigned int str2num(char *str){
unsigned int num=0,digit=0;
while (*str!=0){
num=num+((*str-48)*upwr(10,digit)); //upwr is unsigned power and works
digit++;str++;
}
return num;
}
Code: Select all
int atoi (char *str) {
int num;
while (*str) {
num = num * 10 + *(str++) - 48;
}
return num;
}
Code: Select all
#include <ctype.h>
char _PDCLIB_digits[] = "0123456789";
int atoi( const char * s )
{
int rc = 0;
char sign = '+';
const char * x;
/* TODO: In other than "C" locale, additional patterns may be defined */
while ( isspace( *s ) ) ++s;
if ( *s == '+' ) ++s;
else if ( *s == '-' ) sign = *(s++);
while ( ( x = memchr( _PDCLIB_digits, *(s++), 10 ) ) != NULL )
{
rc = rc * 10 + ( x - _PDCLIB_digits );
}
return ( sign == '+' ) ? rc : -rc;
}
Correct:Jordan3 wrote: i thought i looked at that function before and it was a return somehting_i_dont_remeber();
Code: Select all
int atoi( const char * s )
{
return (int) _PDCLIB_atomax( s );
}