Showing posts with label How to convert string to integer value without using atoi function.. Show all posts
Showing posts with label How to convert string to integer value without using atoi function.. Show all posts

Wednesday, March 16, 2011

How to convert string to integer value without using atoi function.

# include "stdio.h"
# include "string.h"
# define MAX 10
int main()
{
int fnStringtoInt(char*);
char cString[MAX];
printf("Enter the integer value to String variable\n");
gets(cString);
printf("The integer value is :%d\n",fnStringtoInt(cString));
return 0;
}

int fnStringtoInt(char *cString)
{
int nValue=0;
while(*cString != NULL)
{
nValue = (nValue*10)+(*cString-'0');
cString++;
}
return nValue;
}


OUTPUT:

Enter the integer value to String variable
1234456
The integer value is :1234456
Press any key to continue . . .