ProAnswers.org

C program to implement the atoi() function

C program to implement the atoi() function

1 Like

The prototype of the atoi() function is …

int atoi(const char *string);

Program:

#include

int myatoi(const char *string);

int main(int argc, char* argv[])
{
printf("
%d
", myatoi(“1998”));
getch();
return(0);
}

int myatoi(const char *string)
{
int i;
i=0;
while(*string)
{
i=(i<<3) + (i<<1) + (*string - ‘0’);
string++;

// Dont increment i!

}
return(i);
}

if needed use stdarg.h