fonctions de la bibliothèque C - atoi ()
C bibliothèque standard - <stdlib.h>
description
C fonction de bibliothèqueint atoi (const char * str) pour convertir un argument de chaîne strpoints à un nombre entier (type type int).
déclaration
Voici () fonction instruction atoi.
int atoi(const char *str)
Paramètres
- str - la chaîne à être convertie en un nombre entier.
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 atoi () est utilisée.
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int val; char str[20]; strcpy(str, "98993489"); val = atoi(str); printf("字符串值 = %s, 整型值 = %d\n", str, val); strcpy(str, "w3cschool.cc"); val = atoi(str); printf("字符串值 = %s, 整型值 = %d\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