string to intger

How to convert string to integer without using library functions in c programming language.

1 Like

If the string has less than 18 characters then do this:

int main()

{

int n; //no of characters

char arr[20]; //string to convert

scanf("%d %s",&n,&arr);

long long num=0; //final ans

for(int i=0; i < n; i++)

{

  num=num*10+(arr[i]-'0');

}

printf("%lld",num);

return 0;

}

this might help you

int main()
{
const char a[10];
int b[10],i;
scanf("%s",a);
for(i=0;a[i]!='\0';i++)
{
    b[i]=a[i];
    printf("%d\n",b[i]);
}
return 0;
}