User Tools

Site Tools


c:stdlib.h:strtol

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdlib.h:strtol [2024/02/16 01:04] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +====== strtol ======
 +<code c>
 +    #include <stdlib.h>
 +    long int strtol(const char *str, char **endptr, int base);
 +</code>
 +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 =====  
 +<code c>
 +/* 
 + * strtol example code
 + * http://code-reference.com/c/stdlib.h/strtol
 + */
 +#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;
 +}
 +</code>
 +
 +==== Output ====
 +
 +    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