Latest web development tutorials

fonctions de la bibliothèque C - atol ()

C bibliothèque standard - <stdlib.h> C bibliothèque standard - <stdlib.h>

description

fonctions de la bibliothèque C pour convertir une chaînelong int atol (const char * str ) Paramètres strsouligné un entier long (type de type long int).

déclaration

Ce qui suit est une fonction instruction atol ().

long int atol(const char *str)

Paramètres

  • str - une chaîne à convertir en un entier long.

Valeur de retour

Cette fonction retourne le temps entier converti s'il n'y a pas la mise en œuvre d'une conversion efficace, zéro est renvoyé.

Exemples

L'exemple suivant illustre la fonction atol () est utilisée.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
   long val;
   char str[20];
   
   strcpy(str, "98993489");
   val = atol(str);
   printf("字符串值 = %s, 长整型值 = %ld\n", str, val);

   strcpy(str, "w3cschool.cc");
   val = atol(str);
   printf("字符串值 = %s, 长整型值 = %ld\n", str, val);

   return(0);
}

Nous allons compiler et exécuter le programme ci-dessus, qui se traduira par ce qui suit:

字符串值 = 98993489, 长整型值 = 98993489
字符串值 = w3cschool.cc, 长整型值 = 0

C bibliothèque standard - <stdlib.h> C bibliothèque standard - <stdlib.h>