What string function is used to convert a string into long value?

This is done by using the function named as atol() . This function atol() is present in the header file named as <stdlib.h>. So when programmers use this function they must include the header file by the statement



#include <stdlib.h>



The syntax for this function is given by



long atol( const char *s)



Here the function atol() converts the string pointed by s into long and the return data type is therefore long. The function atol() starts with string which may have numeric and non numeric value and the function atol gets terminated when it encounters a non numeric character in the string. So for getting output from this function it must have at least a numeric character starting in the string.


Let us consider the above function by means of an example:



main()

{

long a;

a= atol(“317.890”);

}



So in the program the function atol() converts starts with numeric character 3 and proceeds till 317 and terminates on encountering the non numeric character “. “ and therefore a gets long value as 317L.

Questions by GeekAdmin   answers by GeekAdmin

Showing Answers 1 - 3 of 3 Answers

I used atlo(),atoi() in unix operating system security module. Embracing is that, I failed on most of the occasions. And some times it gives GARBAGE values along with the answer.

Can anyone check this, if possible with an eg.., for this

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions