
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C library function - atol()
Description
The C library function long int atol(const char *str) converts the string argument str to a long integer (type long int).
Declaration
Following is the declaration for atol() function.
long int atol(const char *str)
Parameters
str − This is the string containing the representation of an integral number.
Return Value
This function returns the converted integral number as a long int. If no valid conversion could be performed, it returns zero.
Example
The following example shows the usage of atol() function.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main () { long val; char str[20]; strcpy(str, "98993489"); val = atol(str); printf("String value = %s, Long value = %ld\n", str, val); strcpy(str, "tutorialspoint.com"); val = atol(str); printf("String value = %s, Long value = %ld\n", str, val); return(0); }
Let us compile and run the above program, this will produce the following result −
String value = 98993489, Long value = 98993489 String value = tutorialspoint.com, Long value = 0
stdlib_h.htm
Advertisements