I have to rewrite the atoi function - that is, convert a string given by a command line argument and convert it to an integer. It works for single digit numbers, but when you give it two or more digits, it only converts the first number. I'm not sure what I'm doing wrong, as the concept seems simple. Take in a string, change it's type, print it on the screen with a new format character. Right?
#include <stdio.h>
int myatoi( char *x );
int main( int argc, char *argv[] ) {
char *x = argv[1];
int y;
printf( "Character : %c\n", *x );
y = myatoi( x );
printf( "Integer : %d\n", y );
return 0;
}
int myatoi( char *x ) {
int y = ( *x - 48 );
return y;
}