c - Atoi return value -


i have question regarding atoi. trying use atoi check if can convert character number, however, if number 0 how around that? understand atoi returns 0 if fails, returns value of number if works, in case 0 fall under both categories.

if use strtol instead, there way check if character in array >= 0, or isn't/doesnt exist @ all.

for instance, if dynamic array consisted of {1 40 500}, , try strtol @ position 8 (just out of bounds), return null or indication atoi/strtol failed

you instead use sscanf read out integer, way check return value of sscanf see if found integer or not

char a[] = "12"; char b[] = "abc"; int n = 0;  assert(sscanf(a, "%d", &n ) == 1); assert(sscanf(b, "%d", &n ) == 0); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -