GeekInterview.com
  I am new, Sign me up!
 
Home C
 

Convert a String into Long Value

 
Category: C
Comments (2)


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>. 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.  To get 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”);
}


In the  above 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.



Read Next: Convert a String into an Integer



 

 

Comments


payel said:

  In java there are methods like parseDouble which convert a string into double and doesn't ignore decimal points. Isn't this possible into C?
February 8, 2008, 11:35 am

lakshm said:

  what is the meaning (abbrvation)for atol
December 25, 2008, 7:17 am

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape