Search
 
SCRIPT & CODE EXAMPLE
 

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
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
C :: adding strings in the list 
C :: bootstrap form 
C :: how to add 1 to 10 in c 
C :: c program to find the frequency of characters in a string 
C :: flip exis in dataframe 
C :: how to take blank space in c scanf 
C :: malloc basics 
C :: declare variables arduino 
C :: identifiers in c 
C :: how to get file size in c 
C :: set the nth bit 
C :: class in oops 
C :: macos prevent disk mounting 
C :: size of pointer in c 
C :: do while loop in c 
C :: access 2d array with pointer c 
C :: how to check the word is present in given char array in c 
C :: define constant c 
C :: how to debug a segmentation fault in c 
C :: loops questions on c 
C :: *= operator 
C :: 2 html 1 javascript 
C :: data-types 
C :: c fibonacci series recursion 
C :: rand in c 
C :: #define _TIMESPEC_DEFINED struct timespec { time_t tv_sec; long tv_nsec; }; 
C :: buble sort in c that ask user input 
C :: c limit value range 
C :: c byte vs char 
C :: command line coursera 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =