I have following thing which i wanted to convert to int.
char *ptr; // this can point to variable length of string
int balance = functionToConverIntoint(ptr)
So is there any such function in C "functionToConverIntoint" which can do this job?
I have following thing which i wanted to convert to int.
char *ptr; // this can point to variable length of string
int balance = functionToConverIntoint(ptr)
So is there any such function in C "functionToConverIntoint" which can do this job?
Check out strtol() and strtoul().
You want to avoid atoi() as it does not have a good way of distinguishing between a string of "0" and an invalid number.
Yes. atoi
is a basic one with very limited error handling capability; strtol
is a better one.