Answers for "how to get string to integer in c"

C
22

string to int c

atoi(str) is unsafe

This is the prefered method:
(int)strtol(str, (char **)NULL, 10)
Posted by: Guest on May-08-2020
0

convert string to int error checking c

const char *number = "10";
char *end;
long int value = strtol(number, &end, 10); 
if (end == number || *end != '' || errno == ERANGE)
    printf("Not a number");
else
    printf("Value: %ld", value);
Posted by: Guest on July-29-2021

Code answers related to "how to get string to integer in c"

Code answers related to "C"

Browse Popular Code Answers by Language