Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

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
        }
    }
}
 
PREVIOUS NEXT
Tagged: #How #convert #string #int #library #functions
ADD COMMENT
Topic
Name
3+4 =