atol
long  atol ( const char * string );
stdlib.h
  cplusplus.com  

Convert string to long.
  Parses string interpreting its content as a number and returns a long value.

Parameters.

string
String representing an integer number. The number is considered until a non-numeric character is found (digits, and signs are considered valid numeric characters for this parameter as specified in format). The format used is:
[whitespaces][+|-][nnnnn]
(where whitespaces are any tab or space character and nnnnn may be any number of digits)

Return Value.
  The converted long integer value of the input string.
  On overflow the result is undefined.
  If an error occurs 0 is returned.

Portability.
  Defined in ANSI-C.

Example.

/* atol example */
#include <stdio.h>
#include <stdlib.h>

main ()
{
  int i;
  char szInput [256];
  printf ("Enter a long number: ");
  gets ( szInput );
  i = atol (szInput);
  printf ("Value entered is %d, and its double %d",i,i*2);
  return 0;
}
Output:
Enter a long number: 567283
Value entered is 567283, and its double 1134566

See also.
  atoi, atof, ecvt, fcvt, gcvt, strtod


© The C++ Resources Network, 2000