convert string to int error checking c

Solutions on MaxInterview for convert string to int error checking c by the best coders in the world

showing results for - "convert string to int error checking c"
Amy
31 Jan 2018
1const char *number = "10";
2char *end;
3long int value = strtol(number, &end, 10); 
4if (end == number || *end != '\0' || errno == ERANGE)
5    printf("Not a number");
6else
7    printf("Value: %ld", value);