Answers for "How to convert string to int without using library functions in c"

C
0

How to convert string to int without using library functions in c

#include <stdio.h>
#include<string.h>

void main()
{
    char input[100];
    int i;
    int sum = 0;
    printf("Type a String which will be converted to an Integer: ");
    scanf("%s", input);

    for (i = 0; i < strlen(input); i++)
    {
        if(input[i]>=48 && input[i]<=57)
        {
             //do something, it is a digit
             printf("%d",input[i]-48);
             //48 is ascii value of 0
        }
    }
}
Posted by: Guest on March-06-2022

Code answers related to "How to convert string to int without using library functions in c"

Code answers related to "C"

Browse Popular Code Answers by Language