User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

Q&A is closed


Table of Contents


    #include <stdlib.h>
    long int strtol(const char *str, char **endptr, int base);

strtol Converting a string to an long integer
str: the string to be converted
endptr: address of a pointer variable that points to the last character read, so the character that is not owned by a number
base: base between 2 and 36

Be found unprefixed numbers, these numbers in base 10 are accepted.
If the base '0 'is specified, the strings make a reference to the basis used
(leading “0x” for hexadecimal, “0” for octal, numbers).

strtol c code example

 * strtol example code
#include <stdio.h>
#include <stdlib.h>
int main ( void )
  char string[] ="20405";
  char *endptr;
  long int number;
  number = strtol(string, &endptr, 10);
  printf("string is %s\n",string);
  printf("long int is %li\n", number);
  return 0;


  user@host:~$ ./strtol
  string is 20405
  long int is 20405

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdlib.h/strtol.txt · Last modified: 2024/02/16 01:04 (external edit)

Impressum Datenschutz